Two Best Non-Overlapping Events
A medium-tier problem at 61% community acceptance, tagged with Array, Binary Search, Dynamic Programming. Reported in interviews at razorpay and 0 others.
Two Best Non-Overlapping Events shows up rarely but hurts candidates who don't nail the pattern. You've got events with start/end times and values. Pick two that don't overlap and maximize total value. This looks like a greedy problem until you hit a wall on time complexity. Razorpay has asked it. The trick isn't obvious without seeing the pattern once. If you blank on the approach during the live OA, StealthCoder solves it invisibly while you stay in control.
Companies that ask "Two Best Non-Overlapping Events"
Two Best Non-Overlapping Events is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe naive greedy approach fails here because picking the highest-value event first doesn't guarantee the best pair. You need Dynamic Programming with Binary Search. Sort events by end time, then use DP to track the maximum value achievable up to each event, with a binary search to find the latest non-overlapping event. Common pitfall: treating this as a simple greedy problem and losing points on time complexity. Another trap: forgetting that you must pick exactly two events, not maximize one. The Binary Search keeps you efficient when the obvious DP recurrence feels too slow. StealthCoder hedges this problem if the pattern didn't stick during prep.
Pattern tags
You know the problem.
Make sure you actually pass it.
Two Best Non-Overlapping Events recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Two Best Non-Overlapping Events interview FAQ
Is this really a medium difficulty problem?+
It sits at medium because the core idea (DP plus binary search) is standard, but the combination isn't immediately obvious. The 60% acceptance rate confirms it punishes candidates who try greedy or miss the overlap-checking logic.
What's the main trick to avoid TLE?+
Sort by end time first, then use binary search to locate the latest non-overlapping event for each position. This keeps you O(n log n) instead of O(n^2). Without binary search, you'll time out on large inputs.
How do I know I need exactly two events?+
The problem title itself says 'Two Best.' You're not maximizing one event or three. You're picking the pair with the highest combined value that don't overlap. Read the constraints carefully.
Does this relate to other topics I should know?+
Yes. It combines Sorting (order events), Dynamic Programming (track best values), and Binary Search (find latest non-overlapping partner fast). Master all three to own this pattern.
How often do companies ask this?+
Low frequency in public reports, but it's the kind of problem that resets candidates if they haven't drilled it. Razorpay has confirmed it. If it hits your OA cold, you'll lose time unless you know the pattern.
Want the actual problem statement? View "Two Best Non-Overlapping Events" on LeetCode →