Dsa
Binary Search
Warm-up
Book Position Finder
You are tasked to find the position of a book in a sorted list of book titles represented by strings. You will perform a binary search to find the index of the specified book title. If the title isn't found, return -1.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000) indicating the number of books.
- The second line contains n space-separated strings representing the book titles in sorted order.
- The third line contains a string representing the book title you need to search for.
Output format:
- Print a single integer: the index of the book title in the list, or -1 if not found.
Example:
Input:
5
A Brave New World Braveheart The Catcher in the Rye The Great Gatsby To Kill a Mockingbird
The Great Gatsby
Output:
3
Key concepts
binary_searcharraysearch
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now