Partition Into Groups of Five Consecutive Values
Problem statement
Given an integer array nums, determine whether all occurrences can be partitioned into groups of exactly five values such that every group can be reordered as x, x + 1, x + 2, x + 3, x + 4.
Each array occurrence must belong to exactly one group. Equal values in the input are separate occurrences. The empty array can be partitioned into zero groups.
Function
canPartitionIntoFiveConsecutiveGroups(nums: int[]) → booleanExamples
Example 1
nums = [1,2,3,4,5,2,3,4,5,6]return = trueThe occurrences form [1,2,3,4,5] and [2,3,4,5,6].
Example 2
nums = [1,2,3,4,5,6]return = falseSix occurrences cannot be divided into groups of five.
Example 3
nums = []return = trueZero groups use every occurrence of the empty input.
Constraints
0 <= nums.length <= 200000.-10^9 <= nums[i] <= 10^9.