Show problems as
Classic problem #2784EasyArrayHash TableSorting

Check if Array is Good

Real-world version: Is the Ticket Roll Standard
Tracked in this browser only
Read Check if Array is Good on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

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