Ctrl K

Read It Aloud

Medium
We build a sequence of digit strings. The first term is "1". Each next term comes from reading the previous one aloud: split it into groups of equal consecutive digits and, for each group from left to right, write its length followed by the digit itself. For example, "3322251" reads as "two 3s, three 2s, one 5, one 1" and turns into "23321511". Return the k-th term of the sequence (counting from one). Try to do it without recursion.
Example 1
k=5 → '111221'

1 → "one 1" = 11 → "two 1s" = 21 → "one 2, one 1" = 1211 → "one 1, one 2, two 1s" = 111221.

Example 2
k=1 → '1'

The first term is simply 1.

Constraints
  • 1 ≤ k ≤ 30
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Repeat-Free Stretch MediumLongest Mirror Fragment MediumReading a Zigzag by Rows MediumLenient Number Reader MediumNumber in Roman Numerals Medium
loading Python…
Input
k=5
Expected
'111221'

Run checks the first 3 tests in your browser. Submit checks all 30 tests on the server, hidden ones included.