MEDIUM
ArraySortingUnion-Find
Updated Sep 2026

Maximum Team Size with Overlapping Intervals

Asked at Salesforce

Problem

Given a list of intervals where each interval represents a team member's availability window, find the maximum number of team members who can form a team by selecting overlapping time windows. This problem reduces to finding the maximum overlap of intervals at any point. Consider edge cases where intervals just touch at endpoints.

Asked At

CompanyDifficulty
SalesforceMEDIUMView all Salesforce questions →

How to Think About It

1.

Start by considering all possible pairs of intervals and checking if they overlap — this gives O(n²) brute force.

2.

Sort intervals by start time so overlapping intervals group together naturally.

3.

Use a sweep line approach: treat each start and end as events, sort them, and track active intervals.

4.

Optimize by using a min-heap to remove intervals that end before new ones start.

5.

The optimal approach is O(n log n) using sorting with sweep-line event processing.

Optimal Approach

Sort all intervals by their start time. Create a list of events where each interval start is +1 and each interval end is -1. Sort events by time (and by end before start for ties if endpoints don't count as overlap). Sweep through events, maintaining a running count of active intervals. Track the maximum count encountered during the sweep. This gives the maximum number of overlapping intervals at any point.

What Trips People Up in Real Interviews

1.

Clarify whether touching endpoints (e.g., [1,2] and [2,3]) count as overlapping.

2.

Ask if intervals are guaranteed to be valid (start ≤ end) or need validation.

3.

Mention that after sorting, you only need a single pass — don't suggest nested loops.

4.

If asked about streaming intervals, discuss how a balanced BST or heap would maintain the sweep.

5.

Discuss time complexity proactively: O(n log n) from sorting dominates the linear scan.

Solution Code

def max_team_size(intervals):
    events = []
    for start, end in intervals:
        events.append((start, 1))
        events.append((end, -1))
    events.sort()
    max_overlap = 0
    current = 0
    for time, change in events:
        current += change
        max_overlap = max(max_overlap, current)
    return max_overlap

Pro at DSA?

Test your skills with a real FAANG-style mock interview.

Start a Mock Interview →

Frequently Asked Questions

What is the Maximum Team Size with Overlapping Intervals problem?

Given a list of intervals where each interval represents a team member's availability window, find the maximum number of team members who can form a team by selecting overlapping time windows. This problem reduces to finding the maximum overlap of intervals at any point. Consider edge cases where intervals just touch at endpoints.

How do you solve Maximum Team Size with Overlapping Intervals?

The optimal approach is described in detail above, including step-by-step walkthroughs, complexity analysis, and solution code in Python. Scroll up to the "Optimal Approach" section.

What companies ask Maximum Team Size with Overlapping Intervals?

Maximum Team Size with Overlapping Intervals is asked at Salesforce. It is a medium difficulty problem.

What are common mistakes on Maximum Team Size with Overlapping Intervals?
  • Clarify whether touching endpoints (e.g., [1,2] and [2,3]) count as overlapping.
  • Ask if intervals are guaranteed to be valid (start ≤ end) or need validation.
  • Mention that after sorting, you only need a single pass — don't suggest nested loops.
  • If asked about streaming intervals, discuss how a balanced BST or heap would maintain the sweep.
  • Discuss time complexity proactively: O(n log n) from sorting dominates the linear scan.