Question bank › Binary Search
Dsa Binary Search Medium

Magic Number Finder

You are given a sorted list of unique integers. Your task is to find a 'magic number', defined as a number that equals its index in the array. Implement a function to search for the first magic number in the list, or return -1 if there is none. Input Format: - The first line contains an integer N, the number of integers. - The second line contains N space-separated integers representing the sorted unique integers. Output Format: - Print the magic number if one exists, otherwise print -1. Example: Input: 5 -10 -5 0 3 4 Output: 3

Key concepts

binary_searchmathematicsarrays

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.