Matching Card Trios
MediumHash Map ยท Snowflake
Each string in cards is a card made of k digits, each 0, 1 or 2. Three cards form a matching trio if, in every digit position, the three digits are either all equal or all different.
Return the number of matching trios, where a trio is any three different positions in cards. Cards at different positions count as different cards even when their strings are equal.
Example 1
- Input:
- cards = ["00", "01", "02", "11", "22"]
- Output:
- 2
- Explanation
00, 01, 02has equal first digits and all different second digits.00, 11, 22is all different in both positions.
Example 2
- Input:
- cards = ["10", "10", "10", "10"]
- Output:
- 4
- Explanation
- Any three of the four equal cards match, giving four trios.
Example 3
- Input:
- cards = ["0", "1", "2", "0"]
- Output:
- 2
Constraints
0 <= cards.length <= 20001 <= k <= 8, and every card has the same lengthk- Every character of every card is
0,1or2