Problem
Ask
Submissions

Problem: Count and Say

Medium
30 min
Explore how to solve the count and say sequence problem by mastering run-length encoding. Understand how to track data efficiently and apply this to permutations, anagrams, and game design. This lesson equips you to implement the sequence and prepares you for related coding interview patterns.

Statement

The “count and say” is a sequence of strings built by describing the previous string:

  • The sequence starts with countAndSay(1) = “1”.

  • For n > 1, countAndSay(n) is created by run-length encoding the string countAndSay(n - 1).

Run-length encoding (RLE) works by grouping identical consecutive characters and replacing each group with the count of characters followed by the character itself. For example, the string “15224” is read as: one 1, one 5, two 2s, and one 4, producing “11152214”.

Given a positive integer n, return the nthn^{th} string in the count-and-say sequence.

Constraints:

  • 11 \leq n 30\leq 30

Problem
Ask
Submissions

Problem: Count and Say

Medium
30 min
Explore how to solve the count and say sequence problem by mastering run-length encoding. Understand how to track data efficiently and apply this to permutations, anagrams, and game design. This lesson equips you to implement the sequence and prepares you for related coding interview patterns.

Statement

The “count and say” is a sequence of strings built by describing the previous string:

  • The sequence starts with countAndSay(1) = “1”.

  • For n > 1, countAndSay(n) is created by run-length encoding the string countAndSay(n - 1).

Run-length encoding (RLE) works by grouping identical consecutive characters and replacing each group with the count of characters followed by the character itself. For example, the string “15224” is read as: one 1, one 5, two 2s, and one 4, producing “11152214”.

Given a positive integer n, return the nthn^{th} string in the count-and-say sequence.

Constraints:

  • 11 \leq n 30\leq 30