Google L3 Phone Screen - Early Careers Role
Anonymous User
2087

Consider a deck of normal playing cards. A playing card is represented as a string, where the first part represents the rank (one of Ace A, 2, 3, 10, Jack J, Queen Q, King K) and the second part represents the suit (one of Clubs C. Diamonds D, Hearts H. Spades S)

Criterion 1: the set has 3 or more cards and all cards in the set have the same rank and any suit. Examples:

AC, AD, AS (Ace of Clubs, Diamonds and Spades) 5C, "5D", "SH", "5S" (Five of Clubs, Diamonds, Spades and Hearts)

Criterion 2: the set has 3 or more cards and all cards in the set have the same suit and consecutive ranks.

1C, 2C, 3C, 4C (1, 2, 3 and 4 of Clubs)

8H, 9H, 10H, JH, QH, KH (8, 9, 10, Jack, Queen and King of Hearts)

Examples of invalid sets:

2C, 3C only two cards are present but a minimum of 3 are required "2C", "3C", "5C": not consecutive ranks as it's missing the 4 of Clubs.

2C, 3C", "4H" not all cards have the same suit (mix of Clubs and Hearts)

Write a function that takes as input a list of cards, and determines if the input is a valid playing card set.

Examples:

Input: [2C, 2S, 2H], Function returns: true

Input: [2C, 3C, 4C], Function returns: true

Input: [2C, 3C, 4H] Function returns: false

Comments (9)