
Problem
Solution
Submissions
Library Management System
Certification: Advanced Level
Accuracy: 33.33%
Submissions: 3
Points: 10
Implement a Python class called LibraryManagementSystem
that simulates a basic library. The system should allow adding books to the library, borrowing books, returning books, and searching for books by title, author, or ISBN. Each book should have attributes like title, author, ISBN, and availability status.
Example 1
- Input: library = LibraryManagementSystem()
- Operations: library.add_book("1984", "George Orwell", "978-0451524935")
- Operations: library.borrow_book("978-0451524935")
- Output: "Book '1984' has been borrowed successfully", False
- Explanation:
- Step 1: Create a LibraryManagementSystem instance.
- Step 2: Add a book to the library.
- Step 3: Borrow the book and return success message.
- Step 4: Show the book's availability status is now False.
Example 2
- Input: library = LibraryManagementSystem()
- Operations: library.add_book("The Great Gatsby", "F. Scott Fitzgerald", "978-0743273565")
- Operations: library.search_by_author("F. Scott Fitzgerald")
- Output: [{"title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "isbn": "978-0743273565", "available": True}]
- Explanation:
- Step 1: Create a LibraryManagementSystem instance.
- Step 2: Add a book to the library.
- Step 3: Search for books by the author.
- Step 4: Return the matching book information.
Constraints
- ISBN must be unique for each book.
- Time Complexity: O(1) for adding books, O(n) for searching where n is the number of books.
- Space Complexity: O(n) where n is the number of books.
- The system should handle cases where a book is not found or already borrowed.
Editorial
My Submissions
All Solutions
Lang | Status | Date | Code |
---|---|---|---|
You do not have any submissions for this problem. |
User | Lang | Status | Date | Code |
---|---|---|---|---|
No submissions found. |
Solution Hints
- Use a dictionary to store books with ISBN as keys
- Implement methods for all library operations (add, borrow, return, search)
- Consider using multiple data structures for efficient searching by different criteria
- Implement proper validation for operations like borrowing an already borrowed book
- Consider implementing a waiting list for borrowed books (optional)
- Use proper error handling and status messages