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 and the second part represents the suit (one of Clubs C. Diamonds D. Hearts H Spades 5).
A valid set of playing cards is a set of playing cards that fulfills one of the two following criteria:
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" (1.e. Ace of Clubs. Diamonds and Spades)
"SC" "SD" "SH", "SS" (1.e. 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. Examples:
"9H", "10H", "JH", "QH", "KH"
Examples of invalid sets:
"2C", "3C": only two cards are present but a minimum of 3 are required
"2C", "3C","5C": missing the 4 of Clubs.
"20", "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