TopCoder problem "OmahaLow" used in SRM 206 (Division I Level One , Division II Level Two)



Problem Statement

    

"Omaha" is a variation of poker in which half of the pot goes to the player(s) with the lowest hand. The game is played with a deck of cards, each with a value between 1 through 13, inclusive. Each player is dealt 4 cards, and then 5 shared cards are dealt face up in the center of the table. Each player makes their lowest possible five-card hand by selecting exactly two of their own cards and exactly three of the shared cards.

In order for a hand to qualify, all five cards must have a value of 8 or lower, and all five cards must have different values. If a player cannot form such a hand, he/she is not eligible to win this half of the pot.

Two low hands are compared by sorting the cards from highest to lowest. Starting from the highest card in each hand, compare corresponding cards in each hand until you find the first two with different values. The hand with the smaller of these two cards is the lower hand, and therefore the winner. For example, "76521" is lower than "86432", because 7 is less than 8. "75421" is lower than "75431" because 2 is less than 3. If both hands have the same five cards, they get an equal share of this half of the pot.

You will be given the five shared cards, and the 4 cards held by one player. The cards will be given as Strings, with each character in each String representing one card. Characters '1' through '9' represent cards of values 1 through 9, 'T' is 10, 'J' is 11, 'Q' is 12, and 'K' is 13. Return a String of 5 characters, representing the 5 cards in this player's lowest hand (as defined above). The cards should be sorted highest to lowest. If the player does not have a qualifying low hand, return an empty String.

NOTE: Ignore anything else you may know about cards and card games. For example, suits are not used to determine low hands, and are not considered in this problem. The cards of value 1 are also known as "aces", but we'll just call them '1' for this problem. Also, a standard deck of cards has 4 cards of each value, but this will not be enforced in the input.

 

Definition

    
Class:OmahaLow
Method:low
Parameters:String, String
Returns:String
Method signature:String low(String sharedCards, String playersCards)
(be sure your method is public)
    
 

Constraints

-sharedCards will contain exactly 5 characters.
-playersCards will contain exactly 4 characters.
-All charaters in sharedCards and playersCards will be one of "123456789TJQK".
 

Examples

0)
    
"123QK"
"45TJ"
Returns: "54321"
The lowest possible hand is "54321", and the player can make that hand by selecting the 1, 2, and 3 from the shared cards, and the 4 and 5 from the player's cards.
1)
    
"55443"
"2345"
Returns: ""
There are only 4 unique cards in all (2, 3, 4, and 5), so it is impossible to form a low hand with 5 unique cards.
2)
    
"1357Q"
"345J"
Returns: "75431"
There are two ways to make the hand "75431": "731" and "54", or "751" and "43".
3)
    
"76285"
"4816"
Returns: "65421"
4)
    
"12345"
"3339"
Returns: ""
5)
    
"58463"
"947K"
Returns: "76543"
6)
    
"67521"
"J859"
Returns: "86521"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2435

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=5852&pm=2435

Writer:

legakis

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Brute Force, Sorting, String Manipulation