Partition a Card Deck into Fifteens
Problem statement
Given the visible values of an entire card deck, decide whether every card can be consumed by partitioning the deck into disjoint groups of exactly three cards whose values sum to 15.
Cards are distinct physical cards even when values repeat. Every card must appear in exactly one group.
Function
canPartitionIntoFifteens(cards: int[]) → booleanExamples
Example 1
cards = [1,5,9,2,6,7]return = trueThe deck can be grouped as (1,5,9) and (2,6,7).
Example 2
cards = [1,1,1]return = falseThe only triple sums to 3.
Example 3
cards = [5,5,5,5,5,5]return = trueTwo identical triples each sum to 15.
Constraints
0 <= cards.length <= 36and its length is divisible by 3.1 <= cards[i] <= 9.