Skip to content

Practice Count and Say

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#38
LeetCode Problem

Count and Say

Problem Statement

Start with countAndSay(1) = "1". Each later term describes consecutive equal-digit runs in the previous term: write the run length followed by its digit, preserving run order. Return the nth term as a string. Separated runs of the same digit must stay separate. Practice approach: Build terms iteratively. Scan the current string with a start pointer and advance until the digit changes, then append the count and digit. Use a fresh output buffer per term. Runtime is proportional to the total characters examined across terms, and space to the largest current term.

Source: Count and Say on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5
Output
"111221"
Explanation

The terms begin 1, 11, 21, 1211, 111221. The last step reads one 1, one 2, and two 1s.

Constraints

1 <= n <= 30

Related LeetCode Problems

Practice more problems similar to Count and Say.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.