AO
Back

Run Length Encoding Problems

Phone ScreenPhone ScreenSoftware Engineer, Machine Learning EngineerLast reported March 2026Low Frequency

Problem Overview

Given a run-length encoded string (e.g., the array {'B','A','A','E','E','E','C'} is encoded as the string "B1A2E3C1"), implement the following using only the encoded representation: 1.

Full problem statement

Given a run-length encoded string (e.g., the array {'B','A','A','E','E','E','C'} is encoded as the string "B1A2E3C1"), implement the following using only the encoded representation:

  1. char Find(int p): Return the character at position p in the original (unencoded) data.
  2. Follow-up — char FindByValue(char target, int left, int right): Find the lexicographically largest character within the index range [left, right] of the original data. The input data is assumed to be sorted.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 1
Trade-off discussion

Implement char FindByValue(char target, int left, int right) that finds the lexicographically largest character in the range [left, right] of the original data. The input is assumed to be sorted. (when: After candidate solves Find(int p))

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Prefix sum array / precomputed offsetsPrecompute cumulative counts for all runs into an array, then use binary search to answer each Find query in O(log n) instead of O(n) linear scan; costs O(n) extra space where n is number of runs.

Practice

Write your own against 6 test cases, or read the worked solution — approach, complexity, and code that runs.
Waymo · Phone Screen · Reported 2× across candidate reports
Is this helpful?