PIXELBANKv9.1.0
Menu

The count-and-say sequence starts with "1" and each subsequent term describes the previous:

  • 1: "1"
  • 2: "11" (one 1)
  • 3: "21" (two 1s)
  • 4: "1211" (one 2, one 1)

Given n, return the nth term.

Example:

Input:
4
Output:
1211
Reasoning:
  • The sequence starts with "1" as the first term.
  • To generate the next term, we describe the previous term: the second term is "11" because the first term has one "1".
  • The third term is "21" because the second term has two "1"s.
  • The fourth term is "1211" because the third term has one "2" and one "1", which leads to the output for the given input n=4n = 4.

Constraints:

  • 1 <= n <= 30
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Count and Say - Easy | PixelBank