FunctionRacerProblemsRace

Count and Say

MediumStringsPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems