Find a Timestamp in a Rotated Sorted Ring Buffer of Logs

Last updated: November 29, 2026

Quick Overview

A circular log buffer stores distinct timestamps in sorted order but the read start is rotated by an unknown offset; given the array and a target timestamp, return its index or -1 in O(log n) time.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


A circular log buffer stores distinct timestamps in sorted order but the read start is rotated by an unknown offset; given the array and a target timestamp, return its index or -1 in O(log n) time.

A Google phone screen question about binary search under a broken invariant, framed around ring buffers used in logging systems. The interviewer checks that you can reason about which half is sorted at every step and that your boundary conditions are airtight.

What the Interviewer Expects
  • Recognizes at least one half of any window is sorted
  • Decides which half to keep using the sorted half's endpoints
  • Uses consistent inclusive bounds and terminates correctly
  • Handles unrotated, single-element, and two-element arrays
  • Explains what breaks if duplicates are allowed
Key Topics to Cover
Binary Search
Arrays
Invariants
Ring Buffer
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
  • Duplicates are allowed; what is the worst-case complexity now?
  • Find the rotation offset (index of the minimum).
  • Find the first timestamp at least as large as the target (lower bound) in the rotated array.
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: rotated ascending array of distinct integers, target integer.
  • Output: index of target or -1.
  • O(log n) time, O(1) space....
High-Level Design

Maintain inclusive bounds lo and hi. At midpoint mid, if a[mid] is the target return it. Otherwise, one side is sorted: if a[lo] <= a[mid] the left half [lo, mid] is sorted, so the target ...


Submit Your Answer
Markdown supported