The count-and-say sequence starts with 1. Each following term is produced by reading the previous term as consecutive runs of equal digits and writing, for each run, its length followed by the digit. For example 21 is read as "one 2, one 1" -> 1211.
The first few terms are 1, 11, 21, 1211, 111221.
Given k, output the k-th term (1-indexed).
One line: an integer k.
One line: the k-th count-and-say term.
Example 1
Input
4
Expected
1211
Explanation
Terms: 1 -> 11 -> 21 -> 1211. The 4th term is '1211'.
Example 2
Input
1
Expected
1
Explanation
The sequence starts at '1'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →