Skip to content
RED SAGSkills
easy15 ptsmatharrays

Missing Ticket Number

Tickets were numbered 0 to n. You are given n distinct ticket numbers in tickets, in any order — exactly one number from the range is missing. Return it.

Aim for O(n) time and O(1) extra space.

Example 1

Input: tickets = [3, 0, 1]
Output: 2

Example 2

Input: tickets = [0]
Output: 1

Constraints

  • 1 <= n <= 10^5
  • All values are distinct and in [0, n].
Hint 1

The numbers 0..n add up to n(n+1)/2.

Hint 2

Subtract every ticket you have from that total.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer

Run checks your code on 2 sample tests. Submit runs all 6 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.