Dsa
Binary Search
Medium
Book Price Search
You manage a bookstore's inventory system that returns the price of a book from a sorted list of prices. Given a list of book prices and a target price, design a function that finds the index of the target price or the next higher price.
Input format:
- The first line contains an integer N, the number of book prices.
- The second line contains N integers of book prices in ascending order.
- The third line contains an integer P, the target price.
Output format:
- Output the index of the target price if found, or the index of the next higher price if not found, or -1 if there is no higher price.
Example:
Input:
4
100 200 300 400
250
Output:
2
Key concepts
binary_searchlist
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