Generate the Nth Term of a Run-Length Look-and-Say Sequence
Last updated: November 29, 2026
Quick Overview
Starting from "1", each term describes the previous one by reading consecutive runs aloud ("1" -> "11" -> "21" -> "1211"). Return the nth term of this sequence.
Meta
November 29, 20260
0
0 solved
Starting from "1", each term describes the previous one by reading consecutive runs aloud ("1" -> "11" -> "21" -> "1211"). Return the nth term of this sequence.
A simulation warm-up in Meta phone screens that is really a run-length encoding exercise. The interviewer checks loop control around runs, string building efficiency, and whether you flush the last run.
What the Interviewer Expects
- Clarify 1-indexing and the seed term
- Implement one run-length encoding step cleanly
- Flush the final run
- Build strings with a list, not repeated concatenation
- Comment on how fast the terms grow
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Write run-length decoding for the same format.
- How long is term 50, roughly, and why?
- Which digits can ever appear in this sequence?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: integer n >= 1. Output: string for term n, where term 1 is "1". Each later term is the run-length reading of the prior one: for each maximal run of the same digit, write the run length followed...
High-Level Design
Simulate n - 1 transitions. Each transition scans the current string with two pointers: i marks the start of a run, j advances while s[j] == s[i]. Emit str(j - i) then s[i], then set i = j. Beca...