← 返回 oracle 的题目列表Partition Unique Cards into Consecutive Groups
类型:online_judge
Given an integer array hand containing no duplicate values and an integer groupSize, determine whether all cards can be partitioned into groups such that:
Every group contains exactly groupSize cards.
Values within every group are consecutive increasing integers.
Return true if such a partition exists; otherwise return false.
Input Format
First line: integers n and groupSize
Second line: n distinct integers representing hand
Output Format
Print true or false.
Constraints
1 <= n <= 2 * 10^5
1 <= groupSize <= n
All values in hand are distinct and fit in a signed 32-bit integer.
Example 1
Input:
6 3
1 2 3 6 7 8
Output:
true
Example 2
Input:
6 3
1 2 3 5 6 7
Output:
true
Example 3
Input:
6 3
1 2 4 5 6 7
Output:
false
Example
Input
6 3
1 2 3 6 7 8
Output
true