Find Valid SET Card Triples
Problem statement
Each card has four attributes: color, shape, number, and shading. Each attribute is encoded as 0, 1, or 2. You are given distinct cards in cards, where cards[i][a] is attribute a of card i.
Three cards form a valid SET if, for each of the four attributes independently, their values are either all the same or all different.
Return every valid triple of card indices [i, j, k] with i < j < k. Return triples in lexicographic order, comparing i, then j, then k. Return an empty array if no SET exists. Input cards are distinct, as in a standard deck; do not reorder them.
Function
findSets(cards: int[][]) → int[][]Examples
Example 1
cards = [[0,1,2,0],[0,0,1,1],[0,2,0,2]]return = [[0,1,2]]For each attribute, the three values are all equal or all different, so these three cards form one SET.
Example 2
cards = [[0,0,0,0],[1,1,1,1],[2,2,2,2],[0,1,2,0]]return = [[0,1,2]]The first three cards differ in every attribute. No triple containing card 3 satisfies the rule in every attribute.
Example 3
cards = [[0,0,0,0],[0,0,0,1],[0,0,1,0]]return = []Every possible triple has an attribute with exactly two equal values, so no valid SET exists.
Constraints
0 <= cards.length <= 81.- Every card has exactly
4attributes. - Every attribute is
0,1, or2. - No two cards have the same four attributes.