Peak Resource Usage Across Weighted Intervals
Reported by candidates from Tekion's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Tekion OA, reported in September 2026, is processing a start before an end at the same timestamp. Then your peak is too high and the tests fail quietly. The problem is weighted interval overlap with half-open [start, end) ranges. Example 3 is the trap: [1,2] and [2,3] must return 9, not 14. With up to 200000 intervals, brute force is dead on arrival. You need a sweep line and a strict tie-break rule. If you blank on the ordering mid-assessment, StealthCoder is the invisible safety net that reads the problem and hands you the sweep.
The problem
Each half-open interval [start, end) consumes a positive number of resources while active. Return the maximum total resource usage at any instant. An interval ending at time t is inactive before an interval starting at t is counted. Function peakResourceUsage(intervals: int[][], resources: int[]) → int Examples Example 1 intervals = [[1,4],[3,5],[4,6]] resources = [3,2,4] return = 6 Case 1 exercises the documented deterministic contract. Example 2 intervals = [[0,1]] resources = [7] return = 7 Case 2 exercises the documented deterministic contract. Example 3 intervals = [[1,2],[2,3]] resources = [5,9] return = 9 Case 3 exercises the documented deterministic contract. Constraints 1 <= intervals.length == resources.length <= 200000. 0 <= start < end <= 10^9. The total active resource count fits a signed 32-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a sweep line over events. For each interval, create a +resource event at start and a -resource event at end. Sort by time, and at equal times put the negative deltas first. That handles the half-open rule: an interval ending at t is gone before one starting at t counts. Then walk the events, keep a running sum, and track the max after each event. Complexity is O(n log n) from the sort, which fits n up to 200000. Pitfalls: sorting by time only and getting an unstable tie order, tracking the max after the end events but before the start events at the same time, and using the wrong sign. The sum fits in a signed 32-bit integer per the constraints, but keep it in a wide type anyway. If the tie-break slips under pressure, StealthCoder is the hedge during the live OA.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Peak Resource Usage Across Weighted 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Tekion's OA.
Tekion reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Peak Resource Usage Across Weighted Intervals FAQ
What's the trick in the Tekion peak resource usage problem?+
Convert each interval into two events, +resource at start and -resource at end. Sort by time, with ends before starts at the same time. Keep a running total and record the max. That's the whole solution, and it runs in O(n log n).
Why does Example 3 return 9 and not 14?+
Intervals are half-open, so [1,2) stops being active at time 2. The interval [2,3) starts at 2, but the first one is already gone. They never overlap, so the peak is the larger single value, 9.
Can I use a difference array instead of sorting?+
Not directly. Times go up to 10^9, so an array indexed by time is too big. You could coordinate-compress the times, but sorting events is simpler and just as fast for 200000 intervals.
What edge cases should I test before submitting?+
Test a single interval, like Example 2. Test back-to-back intervals that touch at one point. Test many intervals sharing the same start. Test fully nested intervals. Touching endpoints is where most wrong answers come from, so check that one first.
How do I prepare for this in 48 hours?+
Write the sweep line from scratch twice. Practice the tie-break on touching intervals until it's automatic. Then try the same idea on meeting rooms style problems. It's one pattern, so you don't need a long plan, just clean event sorting.