Practice/Google/Leetcode 1296. Divide Array in Sets of K Consecutive Numbers
CodingMust
You are given an array of integers nums and an integer k. Your task is to determine whether it's possible to divide the array into groups where:
k elementsk consecutive integers (in any order)Return true if such a partition exists, otherwise return false.
k consecutive integerskkExample 1:
Input: nums = [1,2,3,3,4,4,5,6], k = 4 Output: true Explanation: We can form two groups: [1,2,3,4] and [3,4,5,6]
Example 2:
Input: nums = [3,2,1,2,3,4,3,4,5,9,10,11], k = 3 Output: false Explanation: We have elements [1,2,3,3,3,4,4,5,9,10,11]. While we can form groups like [1,2,3], [2,3,4], [3,4,5], we cannot form a valid group containing 9 because we'd need 7 and 8 which don't exist.
Example 3:
Input: nums = [1,2,3,4,5], k = 5 Output: true Explanation: All elements form one consecutive group
Example 4:
Input: nums = [1,1,1,1], k = 1 Output: true Explanation: Each element forms its own group of size 1