Library System
Books, members, borrowing, returning and availability โ with a 3-book limit.
๐งฉ 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
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