class RunLengthString:
One first-hand report, from a Waymo phone screen: the candidate went on to the onsite. The original data B A A E E E C is run-length encoded as B1A2E3C1: each character followed by how many times it repeats. The reported functions are char Find(int p) and the follow-up char FindbyValue(char target, int left, int right), both working on the encoded data.
Here they are methods of a class built from the encoded string: RunLengthString(encoded). Indices are 0-based positions in the original data. Answer without decoding the string. The class and method names are our setup.
Part 1 — Character at an index
Write find(p: int) -> str: the character at index p of the original data. A count can have more than one digit (A12 is twelve As).
Standard explanation — no candidate report records what the interviewer accepted here.
The report gives only the signature and 'find the bigger char'. Ask what 'bigger' means. On sorted data the run characters are sorted, so locate the runs holding left and right and binary-search their characters.
One Waymo phone-screen report, from a candidate who passed it and was then rejected after the onsite. The report gives the example (B A A E E E C encoded as B1A2E3C1), the function char Find(int p) with p an index into the original data, and the follow-up char FindbyValue(char target, int left, int right): 'find the bigger char in range [left, right]', with the input assumed sorted. It says nothing more about the follow-up's meaning, so ask.
One first-hand report, from a Waymo phone screen: the candidate went on to the onsite. The original data B A A E E E C is run-length encoded as B1A2E3C1: each character followed by how many times it repeats. The reported functions are char Find(int p) and the follow-up char FindbyValue(char target, int left, int right), both working on the encoded data.
Here they are methods of a class built from the encoded string: RunLengthString(encoded). Indices are 0-based positions in the original data. Answer without decoding the string. The class and method names are our setup.
Part 1 — Character at an index
Write find(p: int) -> str: the character at index p of the original data. A count can have more than one digit (A12 is twelve As).
Part 2 — A bigger character in a sorted range
Reported follow-up: assume the original data is sorted. Write find_by_value(target: str, left: int, right: int) -> str | None: the report says "find the bigger char in range [left, right]". This page returns the smallest character in the inclusive index range [left, right] that is greater than target, and None when there is none. Ask what "the bigger char" means: the tests use ranges where it gives the same answer as "the largest character in the range, if it is bigger than target".
Implement char FindbyValue(char target, int left, int right): find the bigger char in the range [left, right] of the original data, assuming the input is sorted. (when: After Find(p))
| Approach | Notes |
|---|---|
| Linear scan of the runs | Walk the runs adding up counts until the one containing p: O(m) per query instead of O(log m) with prefix sums and binary search. |
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.