Question bank › Binary Search
Dsa Binary Search Hard

Temperature Record Finder

You have been given a log of temperatures recorded over several days stored in a sorted array. Your task is to identify the earliest day when the temperature equaled or exceeded a given threshold temperature. If the threshold is reached, return the 1-based index of that day. If no day meets or exceeds the threshold, return -1. Input format: - The first line contains an integer n (1 <= n <= 10000): the number of recorded days. - The second line contains n integers (-100 <= temperatures[i] <= 100): the temperatures recorded, sorted in non-decreasing order. - The third line contains an integer threshold (-100 <= threshold <= 100): the threshold temperature. Output format: - A single integer representing the 1-based index of the day or -1 if not found. Example: Input: 5 10 15 20 25 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.