Quant Memo
Coding/●●●●●

The look-and-say next term

Asked at Optiver

The look-and-say sequence builds each term by reading the previous one aloud in runs: "1211" is "one 1, one 2, two 1s," which you write as "111221". Given one term (a string of digits), produce the next term.

"1"       ->  "11"        # one 1
"1211"    ->  "111221"    # one 1, one 2, two 1s
"111221"  ->  "312211"    # three 1s, two 2s, one 1

Return the next term in O(n)O(n) time.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions