Find the Peak Battery Temperature in a Unimodal Thermal Log
Last updated: November 29, 2026
Quick Overview
During a stress test, an iPhone's battery temperature strictly rises and then strictly falls. Given the sampled temperatures, return the index of the peak in O(log n) time.
Apple
November 29, 20260
0
0 solved
During a stress test, an iPhone's battery temperature strictly rises and then strictly falls. Given the sampled temperatures, return the index of the peak in O(log n) time.
A short binary search question with a hardware testing framing, appropriate for Apple's early screens. The interviewer checks that you compare mid with mid + 1 and that you keep the invariant clean.
What the Interviewer Expects
- Compare temps[mid] with temps[mid + 1] to decide the side
- Maintain the invariant that the peak is in [lo, hi]
- Terminate when lo equals hi
- Handle a log that only rises or only falls
- State O(log n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- The log may have plateaus of equal readings; what breaks?
- There may be several local peaks; find any one.
- Find the time the temperature first crossed 40 degrees on the way up.
- The log is on a slow device and each read is costly; minimize reads.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a non-empty list temps that strictly increases then strictly decreases (either part may be empty). Output: index of the maximum....
High-Level Design
If temps[mid] < temps[mid + 1], we are on the rising slope, so the peak is strictly to the right: set lo = mid + 1. Otherwise we are at the peak or on the falling slope, so the peak is at mid or t...