Description
The count-and-say sequence is a sequence of digit strings defined recursively. Given a positive integer n, return the nth element of the count-and-say sequence.
Examples
Input:
n = 4Output:
"1211"Explanation:
1 → 11 → 21 → 1211.
Input:
n = 1Output:
"1"Explanation:
The sequence starts with '1' as the base case. For n=1, we simply return this initial value without any 'count and say' transformation.
Input:
n = 6Output:
312211Explanation:
Building step by step: n=1 is '1'. n=2: read '1' as 'one 1' → '11'. n=3: read '11' as 'two 1s' → '21'. n=4: read '21' as 'one 2, one 1' → '1211'. n=5: read '1211' as 'one 1, one 2, two 1s' → '111221'. n=6: read '111221' as 'three 1s, two 2s, one 1' → '312211'.
Constraints
- •
1 ≤ n ≤ 30