Question bank › Binary Search
Dsa Binary Search Medium

Temperature Record Search

A weather station records daily temperatures in a year. The temperatures are sorted in ascending order. Given a target temperature, find if it is recorded in the list. If found, return the index of the first occurrence; otherwise, return -1. Input format: - The first line contains an integer n, the number of days (1 ≤ n ≤ 365). - The second line contains n sorted integers (the temperatures). - The third line contains the target temperature t. Output format: - Print the index of the first occurrence of t or -1 if not found. Example: Input: 7 10 12 14 14 15 17 20 14 Output: 2

Key concepts

binary_searcharrayssorting

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.