Question bank › Binary Search
Dsa Binary Search Warm-up

User ID Finder

You are given a sorted list of user IDs in ascending order. Your task is to find the position of a specific user ID in this list using binary search. If the ID does not exist, return -1. Input format: - The first line contains an integer n (1 ≤ n ≤ 1000) representing the number of user IDs. - The second line contains n space-separated integers representing the user IDs. - The third line contains an integer representing the user ID you need to search for. Output format: - Print a single integer: the index of the user ID, or -1 if not found. Example: Input: 5 1001 1002 1003 1004 1005 1003 Output: 2

Key concepts

binary_searcharraysearch

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.