Question bank › Binary Search
Dsa Binary Search Hard

Inventory Stock Checker

You manage a warehouse and have an array representing the stock levels of different items. You need to determine if a specific item level is present in your inventory and return the position of its first occurrence. The inventory is sorted in increasing order of stock levels. If the stock level is found, return its 0-based index. Return -1 if not found. Input format: - The first line contains an integer n (1 <= n <= 10000): the number of items. - The second line contains n integers (0 <= stock[i] <= 10000): the stock levels sorted in increasing order. - The third line contains an integer target (0 <= target <= 10000): the item stock level you want to check. Output format: - A single integer representing the 0-based index of the item stock level or -1 if not found. Example: Input: 6 5 10 15 20 20 30 20 Output: 3

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.