Dsa
Binary Search
Medium
Targeted Temperature Search
You are given a list of temperatures in ascending order, and a target temperature. Write a program that finds the index of the target temperature in the list using binary search. If the target temperature is not found, return -1.
Input format:
- The first line contains an integer N, the number of temperatures.
- The second line contains N integers, the temperatures in ascending order.
- The third line contains an integer T, the target temperature.
Output format:
- Output a single integer, which is the index of the target temperature, or -1 if not found.
Example:
Input:
5
10 20 30 40 50
30
Output:
2
Key concepts
binary_searcharray
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