Dsa
Binary Search
Medium
Book Edition Search
A bookstore maintains a sorted array of unique edition identifiers for their books. Write a program that finds the index of a specified edition ID. If the edition ID does not exist, return the index where it can be inserted to maintain the sorted order.
Input Format:
- The first line contains a space-separated list of integers (edition IDs).
- The second line contains a single integer (target edition ID).
Output Format:
- A single integer representing the index of the target or the position to insert it.
Example:
Input:
101 102 103 104 105
102
Output:
1
Key concepts
binary_searcharrayseditions
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