Dsa
Binary Search
Medium
Temperature Record Analysis
You are given a sorted list of recorded temperatures for a week. Given a target temperature, determine the closest recorded temperature that is less than or equal to the target. If no such temperature exists, return -1.
Input Format:
- The first line contains an integer N, the number of recorded temperatures.
- The second line contains N space-separated integers representing the sorted temperatures.
- The third line contains the target temperature.
Output Format:
- Print the closest temperature that is less than or equal to the target or -1 if none is found.
Example:
Input:
7
15 16 20 22 25 30 35
21
Output:
20
Key concepts
binary_searchdata_analysisarrays
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