Ctrl K

Ticket Numbers Without Gaps

Easy
A cashier gathered a stack of sold tickets and wrote their numbers into the array tickets in no particular order. The stack is complete if the numbers run consecutively with no gaps and no repeats: if x is the smallest number and n is the number of tickets, then every number from x to x + n - 1 must appear exactly once. Return True if the stack is complete, and False otherwise.
Example 1
tickets=[14, 12, 15, 13] → True

The smallest number is 12 and there are 4 tickets, so 12, 13, 14 and 15 are needed. All are there.

Example 2
tickets=[5, 7, 6, 6] → False

The numbers 5, 6, 7 and 8 are needed, but instead of 8 there is a second ticket 6.

Example 3
tickets=[0, 2] → False

The numbers 0 and 1 are needed, and 1 is missing.

Constraints
  • 1 ≤ len(tickets) ≤ 10⁵
  • -10⁹ ≤ tickets[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyDoes Any Value Repeat EasyThe Lost Ticket EasyValues in Both Lists EasyShared Values With Repeats Easy
loading Python…
Input
tickets=[14, 12, 15, 13]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 134 tests on the server, hidden ones included.