๐Ÿ“š

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