Partition Into Groups of Five Consecutive Values
Updated
Problem statement
You are given an integer array nums. Can you split all of its values into groups of exactly five, where each group's values can be put in the order x, x + 1, x + 2, x + 3, x + 4? Return true if you can, and false otherwise.
Every value in the array must go into exactly one group. If a value appears more than once, each copy counts as a separate value. An empty array counts as split into zero groups.
Function
canPartitionIntoFiveConsecutiveGroups(nums: int[]) → booleanExamples
Example 1
nums = [1,2,3,4,5,2,3,4,5,6]return = trueThe values split into [1,2,3,4,5] and [2,3,4,5,6]. Each group is five values in a row, so the answer is true.
Example 2
nums = [1,2,3,4,5,6]return = falseThere are six values, and six values cannot be split into groups of five. So the answer is false.
Example 3
nums = []return = trueThe array is empty, so zero groups already use every value. The answer is true.
Constraints
0 <= nums.length <= 200000.-10^9 <= nums[i] <= 10^9.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Nickname-Constrained GroupingZoox · ONSITE INTERVIEW
- Partition Into K-Size Consecutive GroupsDream11 · ONSITE INTERVIEWDream11 interview questions
- Find Max Health SumAmazon · OA
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions