Dsa
Binary Search
Hard
Temperature Converter
You are developing a temperature converter for a weather app. Given a sorted list of temperature values in Celsius and a target temperature in Fahrenheit, your task is to find the closest Celsius temperature to the target Fahrenheit temperature. The conversion formula is: F = C * 9/5 + 32. Your program should read the list of Celsius values and the target Fahrenheit value, and print the closest Celsius temperature.
Input Format:
- The first line contains an integer n (1 <= n <= 100,000) indicating the number of Celsius temperatures.
- The next n lines each contain one Celsius temperature.
- The final line contains the target Fahrenheit temperature.
Output Format:
- Print the closest Celsius temperature rounded to the nearest integer.
Example:
Input:
5
0
25
50
75
100
79
Output:
26
Key concepts
binary_searchmatharrays
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