Best Poker Hand

You are given an integer array ranks and a character array suits. You have 5 cards where the i^th card has a rank of ranks[i] and a suit of suits[i].

The following are the types of poker hands you can make from best to worst:

  • "Flush": Five cards of the same suit.
  • "Three of a Kind": Three cards of the same rank.
  • "Pair": Two cards of the same rank.
  • "High Card": Any single card.

Return a string representing the best type of poker hand you can make with the given cards.

Note that the return values are case-sensitive.

Example 1
Inputranks = [13,2,3,1,9], suits = ["a","a","a","a","a"]
Output"Flush"
The hand with all the cards consists of 5 cards with the same suit, so we have a "Flush".
Example 2
Inputranks = [4,4,2,4,4], suits = ["d","a","a","b","c"]
Output"Three of a Kind"
The hand with the first, second, and fourth card consists of 3 cards with the same rank, so we have a "Three of a Kind".

Constraints

  • ranks.length == suits.length == 5
  • 1 <= ranks[i] <= 13
  • 'a' <= suits[i] <= 'd'
  • No two cards have the same rank and suit.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate