Longest Run of Consecutive Episode Numbers Watched on Xigua Video
Last updated: November 29, 2026
Quick Overview
Given an unsorted list of episode numbers a user has watched in a series (with possible repeats), return the length of the longest run of consecutive episode numbers in O(n) time.
ByteDance
November 29, 20260
0
0 solved
Given an unsorted list of episode numbers a user has watched in a series (with possible repeats), return the length of the longest run of consecutive episode numbers in O(n) time.
A common first-round coding question for ByteDance backend engineers, framed around Xigua Video binge tracking for a 'continue the series' card. The interviewer wants you to reject sorting once O(n) is required and justify why the set-based scan is linear.
What the Interviewer Expects
- Notice sorting gives O(n log n) and ask whether that is acceptable
- Use a hash set and only start counting from run starts
- Argue the amortized O(n) bound clearly
- Handle duplicates and negative numbers
- Write clean code with no off-by-one errors
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
- Return the actual run (start and end), not just the length.
- How would you maintain the answer as new watch events stream in?
- What changes if the data is too large for one machine's memory?
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: a list of integers, possibly unsorted, with duplicates. Output: the length of the longest set of values v, v+1, ..., v+m-1 all present. Empty input returns 0. The target is O(n) expected time, ...
High-Level Design
Put every episode number into a set. A value starts a run only if value - 1 is absent. From each start, extend forward while the next number exists. Because we only extend from starts, each number is ...