Dsa
Binary Search
Medium
Employee ID Search
You are given a sorted list of unique employee IDs in a company. Develop a program that finds the index of a specified employee ID. If the ID does not exist in the list, return the index at which it can be inserted while maintaining the sorted order.
Input Format:
- The first line contains a space-separated list of integers (employee IDs).
- The second line contains a single integer (the target employee ID).
Output Format:
- A single integer representing the index of the target ID or the position it can be inserted.
Example:
Input:
1001 1005 1010 1020 1035
1007
Output:
2
Key concepts
binary_searcharrayssearching
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