Dsa
Sorting
Warm-up
Smart Thermostat Log
A smart thermostat logs the temperature every hour. Due to a network glitch, the logs are out of order. Each log entry contains an Hour (0-23) and a Temperature (integer). You need to output the temperatures in order from the earliest hour to the latest. If an hour is missing, do nothing for that hour. If an hour appears twice, use the one with the higher temperature.
Input: First line N. Next N lines: Hour Temperature.
Output: The temperatures from hour 0 to 23 (if present), separated by spaces.
Example Input:
4
15 22
3 18
15 25
0 15
Example Output:
15 18 25
Key concepts
sortingdata processing
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