Dsa
Binary Search
Medium
Temperature Days Search
Given an array of integers representing daily temperatures, where each element is the temperature for a day, write a program that finds the index of the first day on which the temperature matches or exceeds a given target. If no such day exists, return -1.
Input Format:
- The first line contains a space-separated list of integers (daily temperatures).
- The second line contains a single integer (the target temperature).
Output Format:
- A single integer representing the index of the first matching day or -1.
Example:
Input:
15 20 24 30 28 26 22
25
Output:
2
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