FastPrepMaximum Non-Overlapping Intervals
Problems/Maximum Non-Overlapping Intervals

Maximum Non-Overlapping Intervals

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a review of a Microsoft software engineering internship. The review lists an interval-scheduling question by name only, next to an LRU cache question, with no input or rules. The round is not named. The review describes one interview with CS-fundamentals questions and two coding problems.

Interval scheduling can mean several tasks. Here it is the classic one. You get up to 10^4 intervals [start, end] with 0 <= start < end <= 10^9. You return the largest number you can choose with no two overlapping. An interval that ends exactly when another starts does not overlap it.

Our version is about 75% the same as the reported question.

You are given a list of intervals, where intervals[i] = [start_i, end_i] is an activity that runs from time start_i to time end_i. Two intervals overlap if they share any time strictly inside both of them. An interval that ends exactly when another starts does not overlap it.

Return the largest number of intervals you can choose so that no two chosen intervals overlap. Intervals may repeat, and the list may be in any order.

Function

maxNonOverlapping(intervals: int[][]) → int

Examples

Example 1

intervals = [[1,3],[2,4],[3,5],[6,8],[7,9]]return = 3

Choose [1, 3], [3, 5] and [6, 8]; the first two only touch at 3, which is allowed. Four is impossible: [1, 3] and [2, 4] overlap, and so do [6, 8] and [7, 9], so at most one interval from each of those pairs can be chosen, plus [3, 5].

Example 2

intervals = [[1,2],[2,3],[3,4],[1,3]]return = 3

[1, 2], [2, 3] and [3, 4] only touch at their ends, which does not count as overlapping, so all three can be chosen.

Constraints

  • 1 <= intervals.length <= 10^4 and intervals[i].length == 2
  • 0 <= start_i < end_i <= 10^9

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Minimum Railway PlatformsMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Minimum Removals for Non-Overlapping IntervalsByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
  • Minimum Points Hitting Every Closed IntervalGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimum Removals for Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Maximum Compatible Time WindowsIBM · OAIBM interview questions
  • Task SchedulingJP Morgan Chase · OAJP Morgan Chase interview questions
  • Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
  • Minimum Appointment Cancellations with a Required BreakMaven Clinic · PHONE SCREENMaven Clinic interview questions
  • Minimum Markers to Clear Line SegmentsHSBC · OAHSBC interview questions

Interview reports that mention this question

  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int maxNonOverlapping(int[][] intervals) {
        // Write your code here.
    }
}
Checking account…