Connection Status:
Competition Arena > Straights
SRM 245 · 2005-06-01 · by Enogipe · Simple Math
Class Name: Straights
Return Type: int
Method Name: howMany
Arg Types: (vector<int>, int)
Problem Statement

Problem Statement

You are playing a game of cards in which the number of straights, i.e., sets of consecutive-valued cards, determines the strength of your hand. You will be given a int[] hand, where the i-th element of hand is the number of cards of value i in your hand. You should return the number of straights of length k. For example, suppose you have the hand:
  • 2 of spades
  • 2 of diamonds
  • 2 of clubs
  • 3 of clubs
  • 4 of hearts
  • 4 of clubs
You would be given hand = { 0, 3, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }. The number of two-card straights is 5:
  • 2 of spades, 3 of clubs
  • 2 of diamonds, 3 of clubs
  • 2 of clubs, 3 of clubs
  • 3 of clubs, 4 of hearts
  • 3 of clubs, 4 of clubs

Notes

  • Straights do not wrap around: if hand is {1,0,0,0,0,0,0,0,0,0,0,0,1}, you have no straights of length 2.

Constraints

  • hand will contain exactly 13 elements.
  • Each element of hand will be between 0 and 4 inclusive.
  • k will be between 1 and 13 inclusive.
Examples
0)
{0,3,1,2,0,0,0,0,0,0,0,0,0}
2
Returns: 5

The example given.

1)
{1,1,1,1,1,1,1,1,1,1,1,1,1}
5
Returns: 9

Say hand[0] references Aces. There are 9 ways to make a straight of length 5: Ace-Five up to Nine-King.

2)
{4,4,4,4,4,4,4,4,4,4,4,4,4}
13
Returns: 67108864
3)
{4,0,4,0,4,0,4,0,4,0,4,0,4}
2
Returns: 0

Straights do not wrap around; we have no straights here.

4)
{1,2,3,4,1,2,3,4,1,2,3,4,1}
1
Returns: 31

Submissions are judged against all 36 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Straights with a public method int howMany(vector<int> hand, int k) · 36 test cases · 2 s / 256 MB per case

Submitting as anonymous