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.
Example 1
Input: n = 5
Output: 111221
Explanation: Each term describes the previous one: "1" is one 1 → "11", which is two 1s → "21", which is one 2 and one 1 → "1211", which is one 1, one 2 and two 1s → "111221".
Example 2
Input: n = 1
Output: 1
Explanation: The first term of the sequence is defined as "1".
Example 3
Input: n = 2
Output: 11
Explanation: The first term "1" is read as "one 1", which is written "11".
Start from "1" and repeatedly describe the previous term: group consecutive equal digits and emit count followed by the digit.
Run checks all cases above. Submit evaluates all test cases.