End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
00DAYS
:
00HOURS
:
00MINUTES
:
00SECONDS
Leetcode Problem 846. Hand of Straights
846. Hand of Straights
Leetcode Solutions
Using a hashmap and sorting
Check if the total number of cards is divisible by groupSize. If not, return false.
Create a hashmap to count the occurrences of each card.
Sort the hand in ascending order.
Iterate through the sorted hand.
a. If the current card's count is 0, continue to the next card.
b. Try to form a group starting with the current card.
c. For each number in the group, check if it exists in the hashmap.
d. If any number is missing or has a count of 0, return false.
e. Decrement the count of each number in the group from the hashmap.
If all groups are successfully formed, return true.