Library Management System - Problem

Design a comprehensive Library Management System using object-oriented programming principles. The system should support core library operations including book borrowing, returning, searching, and overdue tracking.

Requirements:

  • Create Book class with properties: id, title, author, isbn, isAvailable
  • Create Member class with properties: memberId, name, borrowedBooks, maxBooks (default 5)
  • Create Library class that manages books and members
  • Implement operations: addBook, addMember, borrowBook, returnBook, searchBooks, getOverdueBooks

The system should handle edge cases like borrowing unavailable books, exceeding member limits, and tracking overdue items (books borrowed for more than 14 days).

Input & Output

Example 1 — Basic Library Operations
$ Input: operations = [["addBook", 1, "1984", "George Orwell", "978-0-452-28423-4"], ["addMember", 101, "Alice Smith", 3], ["borrowBook", 101, 1]]
Output: ["Book 1984 added", "Member Alice Smith added", "Book 1984 borrowed by Alice Smith"]
💡 Note: First add a book with ID 1, then add member Alice with limit 3 books, then Alice successfully borrows the book.
Example 2 — Search and Limits
$ Input: operations = [["addBook", 2, "Animal Farm", "George Orwell", "978-0-452-28424-1"], ["addMember", 102, "Bob Jones", 1], ["borrowBook", 102, 2], ["borrowBook", 102, 2], ["searchBooks", "Orwell"]]
Output: ["Book Animal Farm added", "Member Bob Jones added", "Book Animal Farm borrowed by Bob Jones", "Member has reached borrowing limit", ["Animal Farm by George Orwell - Borrowed"]]
💡 Note: Add book and member with 1-book limit. Bob borrows successfully, then fails due to limit. Search finds Orwell's book showing Borrowed status.
Example 3 — Return Book
$ Input: operations = [["addBook", 3, "Brave New World", "Aldous Huxley", "978-0-06-085052-4"], ["addMember", 103, "Carol White"], ["borrowBook", 103, 3], ["returnBook", 103, 3], ["searchBooks", "Brave"]]
Output: ["Book Brave New World added", "Member Carol White added", "Book Brave New World borrowed by Carol White", "Book Brave New World returned", ["Brave New World by Aldous Huxley - Available"]]
💡 Note: Complete borrow-return cycle. Carol borrows and returns the book. Search confirms book is Available again.

Constraints

  • 1 ≤ operations.length ≤ 1000
  • Each operation has valid parameters
  • Book IDs and Member IDs are unique positive integers
  • Member names and book titles are non-empty strings
  • maxBooks is between 1 and 10 if specified

Visualization

Tap to expand
INPUTLibrary OperationsaddBook(1, "1984", "Orwell"...)addMember(101, "Alice", 3)borrowBook(101, 1)searchBooks("Orwell")returnBook(101, 1)Sequential operationson library systemALGORITHMOOP Design Pattern1Book Classid, title, author, isAvailable2Member ClassmemberId, name, borrowedBooks3Library ClassHashMap for O(1) lookups4Operationsborrow, return, search, overdueKey: Hash MapsbookId → Book ObjectmemberId → Member ObjectRESULTOperation Results"Book 1984 added""Member Alice Smith added""Book 1984 borrowed by Alice"["1984 by Orwell - Borrowed"]"Book 1984 returned"Each operation returnssuccess/failure messageor search resultsKey Insight:Proper OOP design with hash maps enables O(1) lookups for efficient library managementoperations while maintaining clean separation of concerns between books, members, and library.TutorialsPoint - Library Management System | Hash Map Approach
Asked in
Amazon 25 Google 18 Microsoft 15 Apple 12
24.5K Views
Medium Frequency
~25 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen