Back to problems Sign in to unlock
Leetcode
Medium
Recursion
Strings
Simulation
Count And Say
Generate the n-th term of the count-and-say sequence by repeatedly describing the previous term.
Acceptance 0%
Problem Statement
Problem
The count-and-say sequence is defined by repeatedly reading the previous term and encoding consecutive identical digits as:
- the count of the group
- followed by the digit being counted
Start with 1 as the first term.
Your task is to return the n-th term of this sequence.
How the sequence grows
111→ one121→ two1s1211→ one2, then one1
Build the sequence until you reach the requested term and return it as a string.
Input Format
- A single integer
nrepresenting the term to generate.
Output Format
- Return the
n-th string in the count-and-say sequence.
Constraints
1 <= nis assumed.- The sequence should be generated exactly as defined by grouping consecutive equal digits.
- Output is a string, not an integer.
Examples
Sample cases returned by the problem API.
Example 1
Input
n = 1
Output
"1"
Explanation
The first term of the sequence is defined to be 1.
Example 2
Input
n = 4
Output
"1211"
Explanation
The sequence is: 1, 11, 21, 1211. The 4th term is 1211.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.