Dsa
Binary Search
Medium
Warehouse Item Locator
You are managing a warehouse inventory and need to find the location of a specific item, identified by an ID stored in a sorted list. Write a program that searches for the item ID and returns its location index.
Input format:
- The first line contains an integer N, the number of items.
- The second line contains N integers representing the sorted list of item IDs.
- The third line contains an integer ID, the item ID to search for.
Output format:
- Output the index of the item ID if found, or -1 if not found.
Example:
Input:
6
2 4 6 8 10 12
8
Output:
3
Key concepts
binary_searchsearch
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