FastPrepPartition a Card Deck into Fifteens

Partition a Card Deck into Fifteens

Meta logoMeta● HardFULLTIMEONSITE INTERVIEW
Learn

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[]) → boolean

Examples

Example 1

cards = [1,5,9,2,6,7]return = true

The deck can be grouped as (1,5,9) and (2,6,7).

Example 2

cards = [1,1,1]return = false

The only triple sums to 3.

Example 3

cards = [5,5,5,5,5,5]return = true

Two identical triples each sum to 15.

Constraints

  • 0 <= cards.length <= 36 and its length is divisible by 3.
  • 1 <= cards[i] <= 9.

More Meta problems

See Meta hiring insights
public boolean canPartitionIntoFifteens(int[] cards) {
    // Write your solution here.
}
cards[1,5,9,2,6,7]
expectedtrue
Checking account…