Back
Close

Timer for Clash of Code

Statement

 Goal

You have to implement a version of the timer in Clash of Code. The timer starts at 5:00 and runs towards 0:00. The timer stop time changes based on players joining.

Here are the rules:
* Every time a player joins the clash, the timer stop time is set to
t - 256 / ( 2^(p - 1) )
where t is current time in seconds and p is the number of players in the room before the new player joined.
* If the result is under 0:00, set it to 0:00.
* If a player joins at the same time the game is supposed to start, set the new timer stop time instead of starting the game.

For example:

At 5:00 the timer starts, and there is one player (the one who started the clash).
At 4:47 the second player joins -> set to start 256 seconds from now, at 0:31.
At 3:56 the third player joins -> set to start 128 seconds from now, at 1:48.
At 3:13 the fourth player joins -> set to start 64 seconds from now, at 2:09.
At 2:09, the game starts.

Output: 2:09

The game starts if:
* The timer reaches the time it is set to stop at, or
* The timer reaches zero and there is more than one player, or
* The clash room is filled (8 players in total, 7 have joined).
Input
First line: An integer n for the number of players who join the clash

The next n lines: Time stamps in the format m:ss (minutes and seconds) at which a player joins the clash
Output
Output the time stamp at which the game starts in the format m:ss.
If no one joined, output NO GAME.
Constraints
n: Between 0 inclusive and 7 inclusive
Time stamps: Between 0:00 exclusive and 5:00 exclusive

The time stamps in the input are always in the right order (no invalid inputs).
Example
Input
1
4:47
Output
0:31

Tags
Time

Difficulty
Easy

Test cases
1 time stamp, timer starts game Test
Input
1 4:47
Output
0:31

1 time stamp, timer starts game Validator
Input
1 4:21
Output
0:05

2 time stamps, timer starts game Test
Input
2 3:55 3:48
Output
1:40

2 time stamps, timer starts game Validator
Input
2 3:04 2:45
Output
0:37

4 time stamps, timer starts game Test
Input
4 4:32 2:50 1:50 0:51
Output
0:19

4 time stamps, timer starts game Validator
Input
4 4:37 4:22 2:43 1:59
Output
1:27

6 time stamps, timer starts game Test
Input
6 4:51 4:29 3:42 2:25 1:48 0:29
Output
2:38

6 time stamps, timer starts game Validator
Input
6 4:56 3:17 1:10 1:07 1:01 0:42
Output
0:45

1 time stamp, timer reaches zero Test
Input
1 2:14
Output
0:00

1 time stamp, timer reaches zero Validator
Input
1 3:51
Output
0:00

2 time stamps, timer reaches zero Test
Input
2 4:14 0:05
Output
0:00

2 time stamps, timer reaches zero Validator
Input
2 3:39 2:02
Output
0:00

4 time stamps, timer reaches zero Test
Input
4 4:36 2:15 1:11 0:19
Output
0:00

4 time stamps, timer reaches zero Validator
Input
4 4:43 2:39 1:13 0:10
Output
0:00

6 time stamps, timer reaches zero Test
Input
6 3:06 2:53 1:32 0:47 0:21 0:06
Output
0:00

6 time stamps, timer reaches zero Validator
Input
6 3:21 3:07 1:50 0:53 0:21 0:05
Output
0:00

7, the room is filled Test
Input
7 4:10 3:29 2:44 2:20 1:56 1:47 1:43
Output
1:43

7, the room is filled Validator
Input
7 4:46 4:25 4:11 3:56 3:26 3:17 3:14
Output
3:14

No one joins Test
Input
0
Output
NO GAME

No one joins Validator
Input
0
Output
NO GAME

Starting time, but someone joins Test
Input
5 4:21 4:01 3:48 3:10 2:38
Output
2:22

Starting time, but someone joins Validator
Input
6 3:46 2:32 2:28 2:17 2:01 1:45
Output
1:37

Down to the last seconds Test
Input
1 4:18
Output
0:02

Down to the last seconds Validator
Input
1 4:17
Output
0:01

Solution language

Solution

Stub generator input