Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-135

Count and Say

Problem

Return the n-th term of the count-and-say sequence, where term 1 is the string 1 and each following term describes the runs of the previous one.

For example 1 becomes 11, then 21, then 1211. Repeat the run-length description n - 1 times and assume n >= 1.

Hint

Each term is the run-length encoding of the previous term, written as count then digit.

Test cases

case 1
in: [1]
expected: "1"
case 2
in: [2]
expected: "11"
case 3
in: [3]
expected: "21"
case 4
in: [4]
expected: "1211"
case 5
in: [5]
expected: "111221"
Starter codePython
def count_and_say(n):
    # Your code here
    pass

5 test cases · run your code against them in the editor