Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Two-Letter Card Game

XPChallenge Points: 20
levelLevel: Medium

You are given an array cards where each card is represented by a 2-letter lowercase string.
You are also given a character x.

In the game:

  • Start with 0 points.

  • Each card is usable only if it contains the letter x.

  • You may form a pair from two compatible cards.

  • Two cards are compatible if they differ in only one of their two positions.

  • When you form a valid pair, remove both cards and gain 1 point.

  • The game ends when no more valid compatible pairs exist.

Your task is to determine the maximum number of points possible.

Example 1:

Input: cards = ["ax", "bx", "ay", "by"], x = "x"

Output: 1

Explanation:

The only usable cards based on x: "ax", "bx" They differ by exactly one character → 1 point.

Example 2:

Input: cards = ["ab", "ac", "cb", "cc"], x = "c"

Output: 1

Explanation:

Cards containing 'c' are "ac", "cb", "cc" Possible compatible pair: "cb" & "cc"

Example 3:

Input: cards = ["az", "bz", "cz", "dz"], x = "y"

Output: 0

Explanation:

No card contains the letter 'y', so no scoring is possible.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result