#3664
Two-Letter Card Game
medium · 12.3% accepted · 120 likes · top 0%
array · hash table · string · counting · enumeration
Description
You are given a deck of cards represented by a string array cards, and each card displays two lowercase letters.
You are also given a letter x. You play a game with the following rules:
- Start with 0 points.
- On each turn, you must find two compatible cards from the deck that both contain the letter x in any position.
- Remove the pair of cards and earn 1 point.
- The game ends when you can no longer find a pair of compatible cards.
Return the maximum number of points you can gain with optimal play.
Two cards are compatible if the strings differ in exactly 1 position.
Solution