Easy

Best Poker HandC++

Full explanation · Time O(1) · Space O(1)

// Time:  O(1)
// Space: O(1)

// freq table
class Solution {
public:
    string bestHand(vector<int>& ranks, vector<char>& suits) {
        static const vector<string> LOOKUP = {"", "High Card", "Pair", "Three of a Kind", "Three of a Kind", "Three of a Kind"};
        if (all_of(cbegin(suits), cend(suits), [&](const auto& x) { return x == suits[0]; })) {
            return "Flush";
        }
        vector<int> cnt(13);
        for (const auto& x : ranks) {
            ++cnt[x - 1];
        }
        return LOOKUP[*max_element(cbegin(cnt), cend(cnt))];
    }
};