Dsa
Binary Search
Easy
Temperature Tracker
A weather station records daily average temperatures sorted in ascending order. Implement a program to determine if there exists a temperature within a specified range. If the temperature exists, return the index of the first instance; otherwise, return -1.
Input format:
- The first line contains an integer n (1 <= n <= 10^5), the number of recorded temperatures.
- The second line contains n space-separated integers representing daily average temperatures.
- The third line contains two integers min_temp and max_temp, the range of temperatures to search for.
Output format:
- Print the index of the first temperature within the specified range if it exists, else print -1.
Example:
Input:
6
20 23 26 29 30 32
25 30
Output:
2
Key concepts
binary_searchsearcharray
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