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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Simulation
Run-length encoding
String building
Two pointers
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported