Available question text
Generate the infinite self-referential binary sequence s (starting "122112...") whose run lengths equal the sequence itself, and return how many '1's appear in the first n characters. The core challenge is to simulate this run-length–defined sequence efficiently (linear in n) to count the ones.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 481. Magical String
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source