Problem Statement
- 2 of spades
- 2 of diamonds
- 2 of clubs
- 3 of clubs
- 4 of hearts
- 4 of clubs
- 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
Definition
- Class:
- Straights
- Method:
- howMany
- Parameters:
- int[], int
- Returns:
- int
- Method signature:
- int howMany(int[] hand, int k)
- (be sure your method is public)
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,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}
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.
{4,4,4,4,4,4,4,4,4,4,4,4,4}
13
Returns: 67108864
{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.
{1,2,3,4,1,2,3,4,1,2,3,4,1}
1
Returns: 31
{3,1,3,2,2,0,4,1,4,2,2,2,1}
3
Returns: 79
{2,2,3,0,1,1,4,2,2,3,2,1,3}
10
Returns: 0
{4,2,3,4,4,3,2,4,3,4,2,3,1}
8
Returns: 47808
{0,2,3,4,4,2,0,0,1,0,3,2,4}
13
Returns: 0
{2,4,2,0,3,4,4,1,1,1,1,0,1}
5
Returns: 68
{1,4,1,4,1,3,3,1,4,3,4,0,2}
6
Returns: 912
{4,0,2,3,0,1,1,1,0,0,4,2,3}
12
Returns: 0
{0,0,3,2,0,4,4,3,2,0,3,2,2}
11
Returns: 0
{4,1,1,4,4,3,4,3,2,1,2,3,0}
4
Returns: 536
{0,3,4,2,1,2,2,4,0,4,2,2,3}
10
Returns: 0
{1,1,0,0,0,4,1,4,2,2,1,4,3}
6
Returns: 320
{1,1,2,2,0,2,0,0,3,3,0,2,1}
8
Returns: 0
{1,1,2,3,1,1,4,3,3,2,3,3,4}
2
Returns: 71
{2,0,0,3,4,1,1,0,3,4,4,4,1}
6
Returns: 0
{1,4,0,3,4,1,2,1,4,4,1,4,3}
12
Returns: 0
{0,1,1,1,0,3,1,1,0,3,2,4,3}
11
Returns: 0
{4,4,4,3,4,0,0,3,1,2,4,4,4}
11
Returns: 0
{3,3,1,3,0,3,2,3,1,1,2,0,2}
4
Returns: 57
{1,3,3,3,3,3,0,4,3,1,3,3,2}
10
Returns: 0
{1,2,4,0,1,1,2,3,1,2,3,0,0}
7
Returns: 36
{0,4,3,3,2,2,2,2,1,1,1,4,0}
13
Returns: 0
{3,0,1,3,4,1,4,0,2,0,4,3,4}
5
Returns: 48
{3,3,0,0,2,1,0,3,0,3,3,2,2}
13
Returns: 0
{0,4,1,2,4,2,3,3,1,4,3,2,0}
7
Returns: 2592
{3,0,4,0,4,2,3,0,2,1,4,0,1}
4
Returns: 0
{0, 3, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
2
Returns: 5
{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1 }
1
Returns: 31
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }
13
Returns: 67108864
{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }
5
Returns: 288
{0, 3, 1, 2, 3, 2, 2, 0, 0, 0, 0, 0, 0 }
4
Returns: 54
{1, 2, 3, 4, 4, 3, 2, 1, 4, 2, 4, 2, 3 }
5
Returns: 1232