Count and Say

The count-and-say sequence starts with "1". Each later term describes the previous one out loud: split it into runs of equal digits, and for each run write how many digits it has followed by the digit. For example "3322251" reads as two 3s, three 2s, one 5, one 1, giving "23321511". Given n, return the nth term.

30:00

Count and Say
medium
Free written solution
Topics
Companies

The count-and-say sequence starts with "1". Each later term describes the previous one out loud: split it into runs of equal digits, and for each run write how many digits it has followed by the digit. For example "3322251" reads as two 3s, three 2s, one 5, one 1, giving "23321511". Given n, return the nth term.

Example 1:
Input: {"n":4}
Output: 1211
Constraints:
  • 1≤n≤301 \leq n \leq 30

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":4}

Term 1 is "1". Each pass reads the current term aloud to build the next one.

term

1

2

3

4

term 1 = say (1 digit)

1

Variables
VariableValue
term1
say1
DepthFunction Call
Stack empty
0/15