PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of interval scheduling and efficient algorithm design for allocating limited time-based resources, including concepts like sorting and priority handling.

  • medium
  • Salesforce
  • Coding & Algorithms
  • Software Engineer

Maximize events attended given date ranges

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given **n events**, where each event *i* can be attended on **any single day** within an inclusive range \([start_i, end_i]\). You can attend **at most one event per day**, and attending an event consumes exactly **one day**. Return the **maximum number of events** you can attend. ### Input - An array `events` of length `n`, where `events[i] = [start_i, end_i]`. ### Output - An integer: the maximum number of events that can be attended. ### Constraints (typical) - `1 <= n <= 1e5` - `1 <= start_i <= end_i <= 1e5` (or up to ~`1e9` in some variants) ### Example - Input: `[[1,2],[2,3],[3,4]]` - Output: `3` - Explanation: Attend the first on day 1, second on day 2, third on day 3.

Quick Answer: This question evaluates understanding of interval scheduling and efficient algorithm design for allocating limited time-based resources, including concepts like sorting and priority handling.

You are given a list of events, where each event is represented as [start_i, end_i]. Event i can be attended on any one day d such that start_i <= d <= end_i. You may attend at most one event per day, and attending an event uses exactly one day. Return the maximum number of events you can attend. The challenge is to choose attendance days so that you attend as many events as possible, especially when many events overlap.

Constraints

  • 0 <= len(events) <= 100000
  • 1 <= start_i <= end_i <= 10^9
  • You can attend at most one event per day

Examples

Input: [[1,2],[2,3],[3,4]]

Expected Output: 3

Explanation: Attend the first event on day 1, the second on day 2, and the third on day 3.

Input: [[1,2],[1,2],[3,3],[1,5],[1,5]]

Expected Output: 5

Explanation: A valid schedule is days 1, 2, 3, 4, and 5 for the five events, so all events can be attended.

Input: [[1,1],[1,1],[1,1]]

Expected Output: 1

Explanation: All three events can only be attended on day 1, but only one event may be attended per day.

Input: []

Expected Output: 0

Explanation: There are no events to attend.

Input: [[5,5],[1,2],[100,100],[2,3],[2,2]]

Expected Output: 5

Explanation: One optimal schedule is day 1 for [1,2], day 2 for [2,2], day 3 for [2,3], day 5 for [5,5], and day 100 for [100,100].

Input: [[1,4],[4,4],[2,2],[3,4],[1,1]]

Expected Output: 4

Explanation: Only four days are usable across these ranges, so at most four events can be attended. One optimal choice uses days 1, 2, 3, and 4.

Hints

  1. Sort events by their start day, then process days in increasing order.
  2. Among all events currently available to attend, it is best to attend the one that ends earliest. A min-heap is useful here.
Last updated: May 4, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimum Sum of Weekly Maximum Costs - Salesforce
  • Solve Two OA Coding Problems - Salesforce (medium)
  • Implement common data-structure and JS tasks - Salesforce (medium)
  • Minimize operations to reduce integer to zero - Salesforce (medium)
  • Implement an LFU cache with O(1) operations - Salesforce (medium)