📚

Library System

Books, members, borrowing, returning and availability — with a 3-book limit.

Project 7Intermediate

🧩 Problem statement

Books start available. Commands: “borrow:MEMBER:TITLE”, “return:MEMBER:TITLE”, “status”. Borrowing fails with “TITLE is not available” if already out, or “MEMBER has too many books” if they already have 3. Successful actions show “OK”. status lists every book as “TITLE: available” or “TITLE: with MEMBER” (in the book list’s order).

📋 Requirements

  • Books
  • Members
  • Borrowing
  • Returning
  • Availability
  • Due dates (extension)

📥 Inputs

  • BOOKS: list of titles
  • COMMANDS: list of commands

📤 Outputs

  • OK / error messages
  • Status lines

📏 Rules

  • A member may hold at most 3 books
  • A book can be with only one member

🚧 Constraints

  • Titles are unique

🧭 Suggested approach

  • BORROWED map: title → member (missing key = available)
  • COUNT map: member → number of books
  • Validate before changing anything

🧠 Required concepts

  • Maps
  • Validation
  • Functions
✏️ Pseudocode editor · dry-run tool · test cases

Design your solution here. Use Run to dry-run it step by step and Run tests to check it. Hints unlock one at a time — try on your own first!

🧪 Edge cases to test

  • Borrowing a book that’s already out
  • A member at the limit
  • Returning then borrowing again

📈 Complexity analysis

Every command is O(1) except status, which is O(number of books).

📖 Solution walkthrough (open after you’ve tried!)

Two maps keep the whole state: who has each book, and how many books each member holds. Borrowing validates both rules before changing anything, so a failed request leaves the library unchanged. Returning undoes both changes.

🚀 Challenge extensions

  • Add due dates and list overdue books
  • Reject returning a book the member doesn’t have
  • Keep a waiting list (queue) per book

← All projects