Question bank › Binary Search
Dsa Binary Search Medium

Book Search

You are given an array of integers representing the IDs of books in a library, and an integer representing a target book ID to find. Write a function that determines whether the target book ID is in the array of book IDs. The array is not necessarily sorted. You must return 'YES' if the target is found and 'NO' otherwise. Input format: - The first line contains an integer n (1 ≤ n ≤ 10^5), the number of books. - The second line contains n space-separated integers, representing the book IDs. - The third line contains a single integer t (1 ≤ t ≤ 10^9), the target book ID. Output format: - Output 'YES' or 'NO' depending on whether the target book ID is found in the array. Example: Input: 5 4 2 1 3 5 3 Output: YES

Key concepts

binary_searchsorting

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.