Count and Say
Practice this coding question on Coding Gurukul.
Problem statement
Start a sequence with the string 1. To produce the next term, read the previous term from left to right in maximal runs of equal digits. For each run, append its length in decimal followed by the repeated digit. For example, 1211 becomes 111221 because its runs are one 1, one 2, and two 1s. Find the nth term.
Input format
One integer n.
Output format
Print the nth term as a string of digits.
Constraints
1 <= n <= 20.
Sample input
4
Sample output
1211
Sign in to run or submit a solution in C++, Java or Python.