The game of Rack-O is played with each player being dealt 10 cards with numbers from
1 to 60 on them. Each player places those cards in the order dealt, from front to back, in
a rack with slots for holding the cards.
Through a series of draws from the draw pile, each player may replace a card in the
rack with the drawn card.
The goal is to have the cards in the rack in ascending order. The first player to do so is
the winner.
In the ACSL version, you will be given the number of slots, s, and the number of cards,
n, in the game. Each card has a unique number, between 1 and n, inclusive. You will be
given s cards to place in the rack, front to back. You will then be given a set of cards
forming the draw pile, that you will try to play in that order. If the cards in the rack are
not already in ascending order, for each card that is drawn, follow these rules in this
order:
1. Except for the first card in the rack, if the drawn card is 1 less than any card
already in the rack, replace the card in the slot before that card with the drawn
card.
2. Except for the last card in the rack, if the drawn card is 1 greater than any card
already in the rack, replace the card in the slot after that card with the drawn
card.
3. For any three cards that are in adjacent slots in the rack, if the card in the middle
is not between the first and last card, but the drawn card is between the first and
last card, replace the one in the middle with the drawn card.
4. If the drawn card is less than the second card in the rack and the first card in the
rack is greater than that second card, replace that first card in the rack with the
drawn card.
5. If the drawn card is greater than the next to last card in the rack and the last card
in the rack is less than that next to last card, replace that last card with the drawn
card.
6. Otherwise, do not use that card and go to the next one.
As soon as the cards in the rack are in ascending order, the game ends and no more
cards are drawn. The value of the rack is the sum of its cards plus bonus points for
having a 3 or more card sequence. Add 5 points per number for each card that is in a
sequence. For example, 45, 46, 47 is 15 points and 3, 4, 5, 6 is 20 points.
Otherwise, when you have finished looking at every card in the draw pile, the value of
the rack is the opposite of how many step-downs there are. For example, in the list 40,
47, 20, 56, 15, 16, 17, there is a step-down after 47 and another one after 56. The
sequence of 15, 16, 17 is not counted because the entire rack is not in ascending order.
Therefore, the value of that rack is -2.
EXAMPLE:
Input:
10 60
40 35 20 56 32 58 42 17 45 34
31 44 10 28 19 46 7 37 162
Output: 341
Explanation:
See the table below for the sequence of moves. The final rack is in ascending order so
output the sum of the numbers in the rack (326) plus the bonus for a 3-card sequence
(15) for the total value of 341.
TABLE: PLEASE CHECK SCREENSHOT
TASK:
Complete the function playRackO
о
The function has 3 parameters, all strings with numbers separated by a single
space: the number of slots and the number of cards, info, in the first string; the
cards in the rack, rack, in the second string, and the cards in the draw pile, pile,
in the third string
The function returns an integer that represents the value of the player's rack at
the end of the game
You may create additional functions that are called from playRacko if needed in solving
the problem.
CONSTRAINTS:
All cards will be unique within the range 1 to n. There will be no more than 20 slots and
no more than 200 possible cards.
Program: PLEASE CHECK SCREENSHOT/n 个
C
hackerrank.com/test/clj0bk3s6oq/questions/14jua 13
A Classes M Gmail
YouTube
Maps Internships >
Rack
Card
Replace
Rule
Lar
2d 23h left
drawn
used
Ο
ΕΙ
1
40 35
31
56
1
14
20 56
15
32 58
16
ALL
42 17
17
45 34
18
19
40 35
44
17
1
20
20 31
21
22
32 58
1
23
42 44
24
45 34
25
40 35
10
40
40
26
4
27
20 31
28
32 58
29
42 44
30
45 34
31
32
10 35
28
ignore
6
33 P
20 31
34
3258
35
4244
45 34
36
10 19
19
35
1
20 31
53°F
Cloudy
Test Re
Q Search CXS XCR b
F
(
V
hackerrank.com/test/clj0bk3s60q/questions/14j0d194goe
C
Classes Gmail
YouTube
Maps Internships >
Gmail
YouTube
10 19 19
35
1
2d 23h left
20 31
32 58
Language Java 8
Environment
1 > import java.io.
42 44
14
45 34
15
class Result {
10 19
46
ALL
=4
16
34
2
17
/*
20 31
18
* Complete 1
32 58
19
*
42 44
20
* The functi
45 34
21
* The functi
22
* 1. STRING
1
10 19 7
ignore
6
23
*
2. STRING
20 31
24
* 3. STRING
32 58
25
*/
42 44
26
45 46
27
public static
28
10 19
37
58
3
29
}
20 31
30
3258
31
}
42 44
32
45 46
33
public class Solutic
34
10 19
20 31
Game
ends
35
Value =
341
public static vo
BufferedRead
(System.in));
36
3237
BufferedWrite
42 44
53°F
Cloudy
4546
Test Results
Custom
Q Search nternships S M Gmail
YouTube
Maps
Autocomplete Ready
C 3
Language Java 8
Environment
1 > import java.io.*; ..
14
15
class Result {
16
17
18
19
*
20
21
22
I
* Complete the 'playRack0' function below.
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. STRING info
23
* 2. STRING rack
24
25
26
27
* 3. STRING pile
*/
public static int playRacko (String info, String rack, String pile) {
28
29
}
30
31
}
32
All Bookmarks
33 public class Solution {
34
35
55
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader (new InputStreamReader
(System.in));
36
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.
Line: 14 Col: 1
Test Results
Custom Input
Search
Submit
Run Code
Run Tests
9:57 PM
4/1/2024
PRE