Skip to the code
cf.
+25 XP

#578 Fewest Invites to Decline

medium

A calendar assistant finds clashes in a busy week. Each meeting invite is [start, end]. Two meetings clash if they share any time; a meeting that starts exactly when another ends does not clash with it.

Write fewestToDecline(invites) that returns the smallest number of invites to decline so that the remaining meetings never clash.

Example 1

Input: invites = [[2,4],[4,6],[6,8],[2,6]]
Output: 1

Decline [2, 6]; the other three run back to back.

Example 2

Input: invites = [[1,2],[1,2],[1,2]]
Output: 2

Only one of the three identical meetings can stay.

Constraints

  • 0 <= invites.length <= 100000
  • -10^6 <= start < end <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).