Practice Find Books with No Available Copies
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: library_books(book_id INT, title VARCHAR, author VARCHAR, genre VARCHAR, publication_year INT, total_copies INT) and borrowing_records(record_id INT, book_id INT, borrower_name VARCHAR, borrow_date DATE, return_date DATE). A NULL return_date means an active loan. Keep books with at least one active loan and active-loan count equal to total_copies. Return book_id, title, author, genre, publication_year, and current_borrowers. Sort by current_borrowers descending, then title ascending. Practice approach: Count only unreturned borrowing records per book, join book details, and compare the count with stock. Returned loans must not affect availability. Count active loans, not all historical transactions.
Source: Find Books with No Available Copies on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
{
"library_books": [
{
"book_id": 1,
"title": "Aster",
"author": "Nia",
"genre": "Fiction",
"publication_year": 2020,
"total_copies": 2
},
{
"book_id": 2,
"title": "Birch",
"author": "Ravi",
"genre": "Science",
"publication_year": 2021,
"total_copies": 2
}
],
"borrowing_records": [
{
"record_id": 1,
"book_id": 1,
"borrower_name": "A",
"borrow_date": "2026-01-01",
"return_date": null
},
{
"record_id": 2,
"book_id": 1,
"borrower_name": "B",
"borrow_date": "2026-01-02",
"return_date": null
},
{
"record_id": 3,
"book_id": 1,
"borrower_name": "C",
"borrow_date": "2025-12-01",
"return_date": "2025-12-20"
},
{
"record_id": 4,
"book_id": 2,
"borrower_name": "D",
"borrow_date": "2026-01-03",
"return_date": null
}
]
}[
{
"book_id": 1,
"title": "Aster",
"author": "Nia",
"genre": "Fiction",
"publication_year": 2020,
"current_borrowers": 2
}
]Aster has two active loans for two copies. Its returned loan is ignored; Birch still has one copy available.
Constraints
Related LeetCode Problems
Practice more problems similar to Find Books with No Available Copies.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.