Maximum Compatible Time Windows
Updated
Problem statement
You are given two integer arrays, startTime and endTime, each of length n. Time window i begins at startTime[i], inclusive, and ends at endTime[i], exclusive.
Select as many pairwise non-overlapping time windows as possible and return the maximum number selected. Because each window is half-open, one selected window may end exactly when another selected window begins.
Function
selectMostCompatibleWindows(startTime: int[], endTime: int[]) → intExamples
Example 1
startTime = [1,1,2]endTime = [3,2,4]return = 2You may select window 0 by itself, or select windows 1 and 2. The latter two are compatible because window 1 ends exactly when window 2 begins.
Example 2
startTime = [1,1,2,3]endTime = [2,3,3,4]return = 3Select windows 0, 2, and 3: [1,2), [2,3), and [3,4).
Example 3
startTime = [5,5,5]endTime = [8,7,6]return = 1All three windows overlap, so at most one can be selected.
Constraints
1 <= n <= 10^5.1 <= startTime[i], endTime[i] <= 10^9.startTime[i] < endTime[i]for every time window.
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Query Type Frequency WindowOA · Seen Oct 2026
Similar questions at other companies
- Minimum Markers to Clear Line SegmentsHSBC · OAHSBC interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Most Disjoint Intervals From Starts and DurationsDocuSign · OADocuSign interview questions
- University Career FairRoblox · OARoblox interview questions
- Minimum Removals for Non-Overlapping IntervalsByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Minimum Appointment Cancellations with a Required BreakMaven Clinic · PHONE SCREENMaven Clinic interview questions
- Minimum Removals for Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions