← DiffPush

Count and Say

Standard Bar Strings Hard · Hard O(2^n) total output size (the string roughly doubles per round) · O(2^n)

The Roster Chant Evolution

A marching band passes a count chant down the ranks. Each round, the cadet holding the chant reads it aloud as runs: how many of the same digit in a row, then the digit itself, run by run. Given the round number, the bandmaster needs the exact chant that round produces.

Input: An integer n, the round index.

Output: Return the chant string for round n under the run-length reading rule.

Constraints

Examples

Example 1

Input: {"n":4}
Output: "1211"
1, 11, 21, 1211 — round 4 reads round 3's "21" as one-2 one-1.

Example 2

Input: {"n":1}
Output: "1"
Round 1 is the fixed seed.

Solve this in your browser →

Also on LeetCode ↗