35. Count and Say
MediumString
The count-and-say sequence is a sequence of digit strings defined by the recursive formula: - countAndSay(1) = "1" - countAndSay(n) is the run-length encoding of countAndSay(n - 1). Run-length encoding compresses a string by replacing each group of consecutive identical characters with the count followed by the character. Given a positive integer n, return the n-th element of the count-and-say sequence.
Examples
Input: 5
Output: 111221
Explanation: 1 -> 11 -> 21 -> 1211 -> 111221.
Constraints
- 1 <= n <= 30
Loading...
Run checks all cases above. Submit evaluates all test cases.