Count and Say
Term 1 of the sequence is 1. To get each next term, read the previous term aloud group by group: for every run of equal digits, write how many there are followed by the digit.
For example 1 is read as "one 1", so term 2 is 11, which is read as "two 1s", so term 3 is 21, then 1211, then 111221. Return term n.
Example 1
n 4
returns "1211"
Terms are 1, 11, 21, 1211.
Constraints
1 <= n <= 15
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Expand Character RangesMedium
- Falling DominoesMedium
- Fit the Capital PatternMedium
- Kth Letter of the Unpacked TextMedium
- Solve for xMedium
- String to IntegerMedium
- Substrings With Every VowelMedium
- Undo the Column ReadMedium