Split a Concatenated Article ID String Into a Fibonacci-Like Sequence

Last updated: November 29, 2026

Quick Overview

A digit string was produced by concatenating integers where each is the sum of the previous two. Recover any such sequence of at least three numbers (no leading zeros, each fits in a signed 32-bit int), or return an empty list.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A digit string was produced by concatenating integers where each is the sum of the previous two. Recover any such sequence of at least three numbers (no leading zeros, each fits in a signed 32-bit int), or return an empty list.

Toutiao log pipelines sometimes lose delimiters, and recovering a sequence from a run of digits is a natural backtracking exercise. Interviewers at ByteDance like this one because pruning matters: once the first two numbers are chosen, the rest is forced, and a candidate who sees that writes a much faster search.

What the Interviewer Expects
  • Use backtracking over split points
  • Reject numbers with leading zeros except a single 0
  • Enforce the 32-bit bound
  • Prune by comparing each candidate with the required sum
  • Recognize that the first two choices determine the whole sequence
Key Topics to Cover
backtracking
pruning
string to integer parsing
search
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
  • How many first-two choices are there, and what is the true complexity?
  • How would you return all valid sequences instead of one?
  • Rewrite it iteratively by enumerating the first two numbers.
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 is a string of digits with length up to around 200. Output is a list of integers F with len(F) >= 3, F[i] + F[i+1] == F[i+2], concatenating back to the input. Pieces cannot have leading ze...

High-Level Design

Run a DFS that, from position start, tries every next piece. Build the value digit by digit so we do not slice repeatedly. Once two numbers are on the stack, the next one must equal their sum: if th...


Submit Your Answer
Markdown supported