dsa · medium
Count and Say
The count-and-say sequence starts at 1. Term i is built by reading term i-1 in groups of equal digits and saying how many, then the digit: 1 → 11 ("one 1") → 21 ("two 1s") → 1211 ("one 2 then one 1").
Arguments
n— 1-based index of the sequence term to return
Given n, return term n as a string. Term 1 is "1".
Example
n = 4 → "1211".
Constraints
1 <= n <= 30 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 1 Expected: 1
Example 2
Input: 4 Expected: 1211