## Hypercube's LeetCode Weekly Contest 51

- Rank:
**197**/ 2879 - Score: 18 / 26
- Finish Time: 01:15:53

The testcases of the third problem in this contest are wrong, one of which is `[[2,3], [5,2], [1,5], [4,2], [4,1]]`

and the expected answer is `[4,1]`

. It seems that they forgot “each element pair `[u, v]`

represents that `v`

is a child of `u`

in the tree.”

### Baseball Game

You’re now a baseball game point recorder.

Given a list of strings, each string can be one of the 4 following types:

`Integer`

(one round’s score): Directly represents the number of points you get in this round.`"+"`

(one round’s score): Represents that the points you get in this round are the sum of the last two`valid`

round’s points.`"D"`

(one round’s score): Represents that the points you get in this round are the doubled data of the last`valid`

round’s points.`"C"`

(an operation, which isn’t a round’s score): Represents the last`valid`

round’s points you get were invalid and should be removed.

Each round’s operation is permanent and could have an impact on the round before and the round after.

You need to return the sum of the points you could get in all the rounds.

**Example 1:**

```
Input: ["5", "2", "C", "D", "+"]
Output: 15
Explanation:
Round 1: You could get 5 points. The sum is: 5.
Round 2: You could get 2 points. The sum is: 7.
Operation 1: The round 2's data was invalid. The sum is: 5.
Round 3: You could get 10 points (the round 2's data has been removed). The sum is: 15.
Round 4: You could get 5 + 10 = 15 points. The sum is: 30.
```

**Example 2:**

```
Input: ["5", "-2", "4", "C", "D", "9", "+", "+"]
Output: 27
Explanation:
Round 1: You could get 5 points. The sum is: 5.
Round 2: You could get -2 points. The sum is: 3.
Round 3: You could get 4 points. The sum is: 7.
Operation 1: The round 3's data is invalid. The sum is: 3.
Round 4: You could get -4 points (the round 3's data has been removed). The sum is: -1.
Round 5: You could get 9 points. The sum is: 8.
Round 6: You could get -4 + 9 = 5 points. The sum is 13.
Round 7: You could get 9 + 5 = 14 points. The sum is 27.
```

**Note:**

- The size of the input list will be between 1 and 1000.
- Every integer represented in the list will be between -30000 and 30000.

**Accepted**in 00:16:09

### Next Closest Time

Given a time represented in the format “HH:MM”, form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused.

You may assume the given input string is always valid. For example, “01:34”, “12:09” are all valid. “1:34”, “12:9” are all invalid.

**Example 1:**

```
Input: "19:34"
Output: "19:39"
Explanation: The next closest time choosing from digits 1, 9, 3, 4, is 19:39, which occurs 5 minutes later. It is not 19:33, because this occurs 23 hours and 59 minutes later.
```

**Example 2:**

```
Input: "23:59"
Output: "22:22"
Explanation: The next closest time choosing from digits 2, 3, 5, 9, is 22:22. It may be assumed that the returned time is next day's time since it is smaller than the input time numerically.
```

**Accepted**in 00:28:55

### Redundant Connection

We are given a “tree” in the form of a 2D-array, with `distinct`

values for each node.

In the given 2D-array, each element pair `[u, v]`

represents that `v`

is a child of `u`

in the tree.

We can remove `exactly`

one redundant pair in this “tree” to make the result a tree.

You need to find and output such a pair. If there are multiple answers for this question, output the one appearing last in the 2D-array. There is always at least one answer.

**Example 1:**

```
Input: [[1,2], [1,3], [2,3]]
Output: [2,3]
Explanation: Original tree will be like this:
1
/ \
2 - 3
```

**Example 2:**

```
Input: [[1,2], [1,3], [3,1]]
Output: [3,1]
Explanation: Original tree will be like this:
1
/ \\
2 3
```

**Note:**

- The size of the input 2D-array will be between 1 and 1000.
- Every integer represented in the 2D-array will be between 1 and 2000.

**TESTCASES ARE WRONG**

### K Empty Slots

There is a garden with `N`

slots. In each slot, there is a flower. The `N`

flowers will bloom one by one in `N`

days. In each day, there will be `exactly`

one flower blooming and it will be in the status of blooming since then.

Given an array `flowers`

consists of number from `1`

to `N`

. Each number in the array represents the place where the flower will open in that day.

For example, `flowers[i] = x`

means that the unique flower that blooms at day `i`

will be at position `x`

, where `i`

and `x`

will be in the range from `1`

to `N`

.

Also given an integer `k`

, you need to output in which day there exists two flowers in the status of blooming, and also the number of flowers between them is `k`

and these flowers are not blooming.

If there isn’t such day, output -1.

**Example 1:**

```
Input:
flowers: [1,3,2]
k: 1
Output: 2
Explanation: In the second day, the first and the third flower have become blooming.
```

**Example 2:**

```
Input:
flowers: [1,2,3]
k: 1
Output: -1
```

**Note:**

- The given array will be in the range [1, 20000].

**Accepted**in 01:15:53