You are given N cards. Each card consists of a suit and a rank. There are four suits, S (Spades), H (Hearts), D (Diamonds) and C (Clubs), and thirteen ranks, ordered (from the lowest to the highest) 2, 3, 4, 5, 6, 7, 8, 9, 10, J (Jack), Q (Queen), K (King) and A (Ace).

Each card is represented by a string in the format "<rank><suit>". For example, 10 of Spades is described as "105", and Queen of Hearts as "QH".

There are six ranked card sets (described in detail below). Sets are ordered by their strength from the weakest to the strongest. Your task is to detect the card sets that can be formed from the given cards. Detecting each card set is scored separately and is worth an equal number of points. If you detect more than one set, select the strongest one.

Write a function:

Results solution(vector<string> &cards);

that, given an array of strings cards, returns a Results object representing the strongest card set that can be formed.

Assume that the following declarations are given:

struct Results { string set_name; vector<string> selected_cards; };

set_name is a string which should be the name of detected set (see below);

selected_cards is a list of strings, which should be made of cards that form the detected set. Cards can be listed in any order.
Card sets:

There are six card sets ordered by their strength from the weakest (single card) to the strongest (a triple and a pair).

Set 1: single card

Name: "single card"

Description: A single card of the highest rank; the suit does not matter.

For example, for cards = ['2H", "4H", "7C", "90", "100", "KS", your function should return:

{ "set_name" = "single card", "selected_cards" = ["KS"]}

Set 2: pair

Name: "pair"

Description: Two cards sharing the same rank; suits do not matter. If there are multiple pairs, return any one with the highest rank.

For example, for cards = ['AS", "10H", "8H", "105", "80"), one of the correct results is:

{ "set_name"= "pair", "selected_cards" ["10H", "105"]}

Set 3: triple
* Name: "triple"

* Description: Three cards sharing the same rank; suits do not matter. If there are multiple ways to choose a triple, return any with the highest rank.

For example, for cards = ["AS", "JS", "AH", "AD", "100", "AC"], one of the correct results is:

{ "set_name" = "triple", "selected_cards" = "AH", "AD", "AC"]

}

Set 4: five in a row

Name: "five in a row"

Description: Five cards of consecutive ranks starting with the highest possible rank; suits do not matter. If there are multiple ways to choose five such cards, return any.

For example, for cards = ["6H", "7S", "8S", "9S", "10S", "JD", "JC", "KC", "AC"], one of the correct results is:

{ "set_name" = "five in a row", "selected_cards" = ["7S", "8S", "9S", "10S", "JC"] }

Set 5: suit

Name: "suit"

* Description: Five cards sharing the same suit; the ranks do not matter. If there are multiple ways to choose five cards with the same suit, choose any set with the highest suit. The order of the suits (from the highest to the lowest) is S, H, D, C.

For example, for cards = ['2D", "4D", "6D", "8D", "9D", "AC", "KC", "QC", "JC", "7C"], one of the correct results is:

{ "set_name" = "suit", "selected_cards" ["2D", "4D", "6D", "8D", "9D"]}

Set 6: a triple and a pair

Name: "a triple and a pair"

* Description: Five cards, consisting of a triple (three cards of the same rank) and a pair (two cards of the same risk). If there are multiple ways to choose this set, choose one with the highest rank of the triple, then one with the highest rank of the pair. The suits do not matter.

For example, for cards = ["10D", "10H", "10C", "2S", "2H", "2D", "JH", "JC"], one of the correct results is:

{ "set_name" = "a triple and a pair", "selected_cards" = ["10D", "10H", "10C", "JH", "JC"] }

Constraints:
assume that integers are within range 1 to 10, elements of all cards are distinct each string is in correct format <rank><suite> this is the questions. # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

# from extratypes import Results  

# def solution(cards):
    # Implement your solution here
    # return Results(set_name=..., selected_cards=...)
from collections import defaultdict
from extratypes import Results

def parse_card(card_str):
    if card_str[:-1] == '10':
        rank = '10'
        suit = card_str[-1]
    else:
        rank = card_str[0]
        suit = card_str[1]
    return (rank, suit)

def rank_value(rank):
    rank_order = "2345678910JQKA"
    return rank_order.index(rank)

def find_single_card(cards):
    highest_card = max(cards, key=lambda card: rank_value(card[0]))
    return Results(set_name="single card", selected_cards=[highest_card[0] + highest_card[1]])

def find_pair(cards):
    rank_count = defaultdict(list)
    for card in cards:
        rank_count[card[0]].append(card)
    pairs = [cards for cards in rank_count.values() if len(cards) >= 2]
    if pairs:
        highest_pair = max(pairs, key=lambda pair: rank_value(pair[0][0]))
        return Results(set_name="pair", selected_cards=[highest_pair[0][0] + highest_pair[0][1], highest_pair[1][0] + highest_pair[1][1]])
    return None

def find_triple(cards):
    rank_count = defaultdict(list)
    for card in cards:
        rank_count[card[0]].append(card)
    triples = [cards for cards in rank_count.values() if len(cards) >= 3]
    if triples:
        highest_triple = max(triples, key=lambda triple: rank_value(triple[0][0]))
        return Results(set_name="triple", selected_cards=[highest_triple[0][0] + highest_triple[0][1], highest_triple[1][0] + highest_triple[1][1], highest_triple[2][0] + highest_triple[2][1]])
    return None

def find_five_in_a_row(cards):
    rank_order = "2345678910JQKA"
    rank_count = defaultdict(list)
    for card in cards:
        rank_count[card[0]].append(card)
    sorted_ranks = [rank for rank in rank_order if rank_count[rank]]
    for i in range(len(sorted_ranks) - 4):
        if all(rank in sorted_ranks[i:i+5] for rank in rank_order[rank_order.index(sorted_ranks[i]):rank_order.index(sorted_ranks[i])+5]):
            selected_cards = [rank_count[rank][0] for rank in rank_order[rank_order.index(sorted_ranks[i]):rank_order.index(sorted_ranks[i])+5]]
            return Results(set_name="five in a row", selected_cards=[card[0] + card[1] for card in selected_cards])
    return None

def find_suit(cards):
    suit_count = defaultdict(list)
    for card in cards:
        suit_count[card[1]].append(card)
    suits = ["S", "H", "D", "C"]
    for suit in suits:
        if len(suit_count[suit]) >= 5:
            selected_cards = suit_count[suit][:5]
            return Results(set_name="suit", selected_cards=[card[0] + card[1] for card in selected_cards])
    return None

def find_triple_and_pair(cards):
    rank_count = defaultdict(list)
    for card in cards:
        rank_count[card[0]].append(card)
    triples = [cards for cards in rank_count.values() if len(cards) >= 3]
    pairs = [cards for cards in rank_count.values() if len(cards) >= 2 and cards not in triples]
    if triples and pairs:
        highest_triple = max(triples, key=lambda triple: rank_value(triple[0][0]))
        highest_pair = max(pairs, key=lambda pair: rank_value(pair[0][0]))
        selected_cards = highest_triple[:3] + highest_pair[:2]
        return Results(set_name="a triple and a pair", selected_cards=[card[0] + card[1] for card in selected_cards])
    return None

def solution(cards):
    parsed_cards = [parse_card(card) for card in cards]
    checks = [
        find_triple_and_pair,
        find_suit,
        find_five_in_a_row,
        find_triple,
        find_pair,
        find_single_card
    ]
    for check in checks:
        result = check(parsed_cards)
        if result:
            return result
 my solution but test cases dont pass. check pls