Check if Array is Good
Real-world version: Is the Ticket Roll StandardThe 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.
def is_standard_roll(nums: list[int]) -> bool:public boolean isStandardRoll(int[] nums)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's