All problems
0857EasyArrayHash TableSorting

Is the Ticket Roll Standard

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2784Check if Array is Good

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A ticket roll is standard when, for some whole number k of at least 1, the numbers printed on it are exactly the numbers 1 through k each appearing once, plus a second copy of k. So a standard roll holds k + 1 tickets in total.

Return true when the roll nums is standard, and false otherwise.

Examples

Example 1

Input
nums = [2, 1, 3, 3]
Output
true

The roll holds four tickets, so a standard roll would need the numbers 1, 2 and 3 with a second 3. Sorted, the roll reads 1, 2, 3, 3, which is exactly that.

Example 2

Input
nums = [1, 2, 3, 4]
Output
false

Four tickets would need a second copy of 3, but every number here appears once and a 4 is present, so the roll is not standard.

Example 3

Input
nums = [2, 2, 1]
Output
true

Three tickets need the numbers 1 and 2 with a second 2, and sorted the roll reads 1, 2, 2.

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 200

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_standard_roll(nums: list[int]) -> bool:
Java
public boolean isStandardRoll(int[] nums)
September 7
Apply