Statistics

Problem Statement for "Omaha"

Problem Statement

PROBLEM STATEMENT
Omaha is a variation of the card game Poker.  The rules are as follows:
Each player holds 4 cards.
There are 5 communal cards on the table, which are part of everyone's total
hand of 9 cards.
Each player must make the best hand possible out of 2 of the cards he/she is
holding and 3 of the cards on the table.

Given a String[] of a player's held cards and a String[] of the communal cards,
return the best hand the player has.

Each element of both of the String[] inputs will be a 2 character String.  The
first character will represent the value and the second will represent the suit.

Here are the card values in increasing order, where 2 is the lowest and A is
the highest:
2,3,4,5,6,7,8,9,T,J,Q,K,A (note the A, or ace, cannot be 1)
Here are the different card suits (order does not matter--there cannot be
flushes possible in 2 different suits):
C,D,H,S

The order of the hands goes as follows:
straight flush (5 cards, sequentially ordered, all of the same suit)
4 of a kind (4 cards of the same value)
full house (3 cards of one value and 2 of another)
flush (5 cards of the same suit)
straight (5 cards sequentially ordered)
3 of a kind (3 cards of the same value)

Each hand beats all the hands below it.  So a straight flush beats everything,
a 4 of a kind beats everything except straight flush, a full house beats
everything except a 4 of a kind and a straight flush, and so forth.

The return will be of the following format (quotes added for clarity):
"THREE OF A KIND ?"
"? HIGH STRAIGHT"
"? HIGH FLUSH"
"FULL HOUSE ? OVER ?"
"FOUR OF A KIND ?"
"? HIGH STRAIGHT FLUSH"
Where the ? represents a single character card value (as shown below).

The following section explains which hand wins given two of the same type:

*straight flush:
The higher straight flush wins.  The method should return "? HIGH STRAIGHT
FLUSH". For example, "5S","6S","7S","8S","9S" beats "4S","5S","6S","7S","8S".
Here, the "9 HIGH STRAIGHT FLUSH" would beat the "8 HIGH STRAIGHT FLUSH" so the
method would return "9 HIGH STRAIGHT FLUSH".
*4 of a kind:
The higher 4 of a kind wins.  The method should return "FOUR OF A KIND ?".  For
example, 4 9s beats 4 4s, and the method would return "FOUR OF A KIND 9", not
the worse "FOUR OF A KIND 4".
*full house:
The full house with the higher value 3 of a kind wins.  After that, choose the
highest possible pair.  For example, "9D","9S","TC","TD","TS" beats
"9C","9D","9S","JD","JS" (since three Ts beats three 9s).  The method should
return "FULL HOUSE ? OVER ?", where the first ? is the three of a kind, and the
second ? is the pair.  Thus in this example, the "FULL HOUSE T OVER 9" beats
"FULL HOUSE 9 OVER J".
*flush:
As mentioned, there can only be a flush of one suit on the table in Omaha.
Choose the highest 3 cards of that suit from the table and the highest 2 cards
of that suit from the player's hand.  The method should return "? HIGH FLUSH".
So for example, "2S","3S","9S","JS","QS" would return "Q HIGH FLUSH".
*straight:
The higher straight wins (same as the rule for straight flush above).  The
method should return "? HIGH STRAIGHT".  Thus "6C","7D","8D","9C","TS" would
return "T HIGH STRAIGHT".
*3 of a kind:
Choose the highest 3 of a kind.  The method should return "THREE OF A KIND ?".
For example, if the best hand is three Ks, the method would return "THREE OF A
KIND K".

DEFINITION
Class name: Omaha
Method name: bestHand
Parameters: String[], String[]
Returns: String
The method signature is:
String bestHand(String[] held, String[] communal)
Be sure your method is public.

TopCoder will ensure the following:
*held will contain exactly 4 elements, formatted as above.
*communal will contain exactly 5 elements, formatted as above.
*all 9 cards will be unique.
*there will be at least a 3 of a kind possible.
*there will be no spaces in the input.

NOTE:
-The return String may not have leading, trailing, or extra spaces.
-For both straight flush and straight, the sequence cannot wrap. For example,
the following sequence is not a straight because "2S" cannot come after "AS":
"2S","3C","4D","5H","AS".

EXAMPLES
All quotes added for clarity

1)
held={"9S","TS","JS","9D"}
communal={"5S","KS","AS","2C","4H"}
The best hand is a flush:
"5S","TS","JS","KS","AS"
"A HIGH FLUSH"

2)
held={"9S","TS","JS","9D"}
communal={"5S","KS","AS","2C","9C"}
Even though there is a 3 of a kind of 9s possible, the flush is still the
highest hand:
"5S","TS","JS","KS","AS"
"A HIGH FLUSH"

3)
held={"4C","4D","TS","JS"}
communal={"5S","KS","AS","4S","4H"}
The 4 of a kind beats the flush.
"FOUR OF A KIND 4"

4)
held={"AS","KS","QS","2C"}
communal={"5S","6S","TD","JD","QC"}
Since you must use 3 cards from the table and 2 from the held cards, a flush
cannot be made.  The best hand is instead the straight:
"TD","JD","QC","KS","AS"
"A HIGH STRAIGHT"

5)
held={"QD","KS","QS","2C"}
communal={"QC","3C","5D","7D","8S"}
The best hand is the three of a kind.
"THREE OF A KIND Q"

6)
held={"QS","QC","3S","4D"}
communal={"5D","5C","QH","7C","8S"}
The best hand is a full house, using the two Qs from the held cards, and the Q
and two 5s from the communal cards.
"FULL HOUSE Q OVER 5"

7)
held={"AS","KS","AC","KC"}
communal={"TS","JS","QS","JC","QC"}
There is a straight flush on the table, using the spades.  The method should
return:
"A HIGH STRAIGHT FLUSH"

Definition

Class:
Omaha
Method:
bestHand
Parameters:
String[], String[]
Returns:
String
Method signature:
String bestHand(String[] param0, String[] param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: