📘
Count and Say
The count-and-say sequence starts with "1" and each subsequent term describes the previous:
- 1: "1"
- 2: "11" (one 1)
- 3: "21" (two 1s)
- 4: "1211" (one 2, one 1)
Given n, return the nth term.
Example:
Input:
4
Output:
1211
Reasoning:
- The sequence starts with "1" as the first term.
- To generate the next term, we describe the previous term: the second term is "11" because the first term has one "1".
- The third term is "21" because the second term has two "1"s.
- The fourth term is "1211" because the third term has one "2" and one "1", which leads to the output for the given input n=4.
Constraints:
- 1 <= n <= 30
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.