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
Coding & Algorithms
Software Engineer
Apple
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
binary search
unimodal arrays
invariants
peak finding
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported