Question Details
Problem
You are given a hand of cards represented as an integer array. Rearrange the cards into groups of exactly k consecutive cards (e.g., [1,2,3], [2,3,4]).
Return True if this is possible, False otherwise.
python
def can_group_cards(hand: list[int], k: int) -> bool:
pass
**Input**: hand = [1, 2, 3, 6, 2, 3, 4, 7, 8], k = 3
Output: True
# Groups: [1,2,3], [2,3,4], [6,7,8]
**Input**: hand = [1, 2, 3, 4, 5], k = 4
Output: False
# 5 cards not divisible into groups of 4
**Input**: hand = [1, 1, 2, 2, 3, 3], k = 3
Output: True
# Groups: [1,2,3], [1,2,3]
Follow-ups
- What is the time complexity of your approach using a sorted map?
- If
kis not fixed — find the minimumk >= 2for which grouping is possible — how do you solve it? - How does this problem relate to LeetCode 846 and 1296? What differs?
- What if cards can be repeated in the same group?
Full Details
Problem
You are given a hand of cards represented as an integer array. Rearrange the cards into groups of exactly k consecutive cards (e.g., [1,2,3], [2,3,4]).
Return True if this is possible, False otherwise.
python
def can_group_cards(hand: list[int], k: int) -> bool:
pass
**Input**: hand = [1, 2, 3, 6, 2, 3, 4, 7, 8], k = 3
Output: True
# Groups: [1,2,3], [2,3,4], [6,7,8]
**Input**: hand = [1, 2, 3, 4, 5], k = 4
Output: False
# 5 cards not divisible into groups of 4
**Input**: hand = [1, 1, 2, 2, 3, 3], k = 3
Output: True
# Groups: [1,2,3], [1,2,3]
Follow-ups
- What is the time complexity of your approach using a sorted map?
- If
kis not fixed — find the minimumk >= 2for which grouping is possible — how do you solve it? - How does this problem relate to LeetCode 846 and 1296? What differs?
- What if cards can be repeated in the same group?
Free preview. Unlock all Ziphq questions →
About This Question
This is a reported interview question from a ziphq interview during the phone round.
It covers the following topics: Arrays, Coding, Phone, Onsite .
More Ziphq Interview Questions
InterviewDB
Catch Me If You Can: Optimal Pursuer Movement on a Grid
InterviewDB
Conditional Check: Evaluate Boolean Expressions with Variables
InterviewDB
Ziphq SWE Phone - Convert Email
InterviewDB
Display Strings: Format and Wrap Text to Fit a Fixed-Width Screen
InterviewDB
Furthest Distance Reachable with Limited Fuel Stops