Majority Labels over Audio Intervals
Reported by candidates from Nooks's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole Nooks problem hinges on one structure: a sweep over endpoints with a live vote count that can hand you the current winner fast. If your Nooks OA invite from July 2026 has this one, "Majority Labels over Audio Intervals" is a sweep line with a heap or ordered map holding label counts. Up to 10^5 intervals means no per-segment rescans. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the pattern is learnable tonight.
The problem
You are given half-open audio intervals intervals[i] = [start, end) and a parallel array labels. Interval i contributes one active vote for labels[i] throughout its covered time. Partition all covered audio at input endpoints. For every resulting covered segment, choose the label with the greatest number of active votes. Break equal vote counts by the lexicographically smaller label. Omit uncovered gaps. Merge adjacent covered result segments exactly when they have the same chosen label. Return the result in start order as rows [start, end, label], with numeric endpoints serialized as decimal strings. Function majorityAudioIntervals(intervals: int[][], labels: String[]) → List<List<String>> Examples Example 1 intervals = [[0,5],[2,7],[4,6]] labels = ["alice","bob","alice"] return = [["0","6","alice"],["6","7","bob"]] alice wins from 0 through 6, including ties by lexicographic order. Only bob remains active from 6 to 7. Example 2 intervals = [[0,3],[1,4],[2,5],[4,6]] labels = ["b","a","a","b"] return = [["0","1","b"],["1","5","a"],["5","6","b"]] At time 1, a ties b and wins lexicographically. Adjacent segments won by a merge through time 5. Constraints 1 <= intervals.length == labels.length <= 10^5 0 <= intervals[i][0] < intervals[i][1] <= 10^9 Every label is a non-empty printable-ASCII string of length at most 30. The returned rows are ordered by start time.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build events: +1 for a label at start, -1 at end. Sort by coordinate. Between consecutive distinct coordinates, you have a segment with a fixed vote set. You need the max count, ties broken by smaller label. Use a max-heap keyed by (-count, label) with lazy deletion: push the new (count, label) on every change, and when reading the top, pop entries whose count doesn't match the current map. Process all events at the same coordinate before reading the winner. If the active total is zero, it's a gap, so skip it and break any merge. Otherwise, if the previous output row ends exactly here with the same label, extend it. The classic pitfalls are reading the winner mid-coordinate, merging across a gap, and forgetting that ends are exclusive. If the heap logic goes sideways live, StealthCoder can hand you a working version.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Majority Labels over Audio 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderYou've seen the question.
Make sure you actually pass Nooks's OA.
Nooks reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Majority Labels over Audio Intervals FAQ
What's the core trick in Majority Labels over Audio Intervals?+
Sweep line over sorted endpoints, with a count map per label and a max-heap for the winner. Apply every event at a coordinate, then read the top. Lazy deletion keeps the heap correct without needing a removal operation.
How hard is this one really?+
Hard-ish. Each piece is standard, but combining sweep, lazy heap, tie-breaking, and merging adjacent rows is where people slip. Expect to spend your time on edge cases, not the idea.
How do I handle ties between labels?+
Key the heap by negative count, then label string. Equal counts then pop the lexicographically smaller label first. Example 2 tests this at time 1, where a ties b and a wins.
When should I merge adjacent segments?+
Merge only when the last output row's end equals the new segment's start and the chosen label is the same. If there's a gap with zero active votes, don't merge, even if the labels match on both sides.
How do I prepare for this in 48 hours?+
Write a sweep line with events sorted by coordinate, then add a lazy-deletion heap. Practice on a small case with a gap and a tie. Make sure you process all events at one coordinate before reading the winner.