Reported September 2026
ByteDancegreedy

Minimum Removals for Non-Overlapping Intervals

Reported by candidates from ByteDance's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ByteDance OA. Under 2s to a working solution.
Founder's read

The ByteDance OA reported in September 2026 looks like an interval problem, but it's really a scheduling problem in disguise. You're picking the largest set of intervals that don't overlap, and the removal count is just total minus kept. If you've seen activity selection, you've seen this. If your brain freezes under the timer, StealthCoder runs invisibly during the live assessment and gives you a working solution as a safety net. Still, the idea fits in one sentence, so read on and lock it in before you sit down.

The problem

You are given a collection of integer intervals intervals, where each interval is represented as [start, end].
Remove the minimum number of intervals so that every pair of remaining intervals is non-overlapping. When one interval ends exactly where another begins, they are compatible and may both remain.
Return the minimum number of intervals that must be removed.

Function
minimumIntervalRemovals(intervals: int[][]) → int

Examples
Example 1
intervals = [[1,2],[2,3],[3,4],[1,3]]
return = 1
Removing [1,3] leaves three pairwise non-overlapping intervals. The intervals [1,2] and [2,3] may both remain because endpoint contact is allowed.
Example 2
intervals = [[1,2],[1,2],[1,2]]
return = 2
At most one of the three identical intervals can remain, so two removals are necessary.
Example 3
intervals = [[-5,-2],[-2,0],[0,1]]
return = 0
Every neighboring pair only touches at an endpoint, so all three intervals may remain.

Constraints
0 <= intervals.length <= 100000.
Every interval has exactly two signed 32-bit integer endpoints [start, end] with start < end.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is greedy by end time. Sort intervals by end ascending. Keep the first one, then walk the rest. If the next start is >= the last kept end, keep it and update the end. Otherwise, count a removal. Touching endpoints are allowed, so the comparison must be >=, not >. That's the most common bug. The second pitfall is sorting by start, which fails on cases like a long early interval blocking many short ones. Also watch the empty input, which returns 0, and the signed 32-bit endpoints, so avoid subtracting values in a way that could overflow. Complexity is O(n log n) for the sort and O(1) extra space. With up to 100000 intervals, that's comfortable. If you blank on why end-time works, StealthCoder is the hedge during the live OA, but the exchange argument is short: finishing earliest leaves the most room.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Minimum Removals for Non-Overlapping Intervals cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as non overlapping intervals. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass ByteDance's OA.

ByteDance reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Removals for Non-Overlapping Intervals FAQ

What's the trick for this ByteDance interval problem?+

Sort by end time and greedily keep every interval whose start is at or after the last kept end. Answer is total count minus kept count. Ending earliest leaves the most room for future intervals, which is why it's optimal.

Why not sort by start time?+

Sorting by start can make you keep a long interval that blocks many short ones. You'd need extra logic to swap in the shorter one. Sorting by end avoids that and keeps the loop simple, with no backtracking.

How do I handle intervals that touch at endpoints?+

Touching is allowed, so [1,2] and [2,3] can both stay. Use start >= lastEnd as the keep condition. Using strict greater-than would wrongly remove the second interval and fail Example 1 with an answer of 2.

What's the time and space complexity?+

Time is O(n log n) from sorting, then one linear pass. Space is O(1) beyond the sort. With n up to 100000 this is fine. Handle the empty array by returning 0 before touching any indexes.

How do I prepare for this in 48 hours?+

Write the end-sorted greedy from memory twice. Test it on the three examples, especially the identical intervals case and the touching endpoints case. Then try a variant, like minimum arrows to burst balloons, to confirm the pattern sticks.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ByteDance.

OA at ByteDance?
Invisible during screen share
Get it