## Hypercube's LeetCode Weekly Contest 52

- Rank:
**244**/ 2615 - Score: 14 / 22
- Finish Time: 01:30:38

### Repeated String Match

Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.

For example, with A = “abcd” and B = “cdabcdab”.

Return 3, because by repeating A three times (“abcdabcdabcd”), B is a substring of it; and B is not a substring of A repeated two times (“abcdabcd”).

**Note:**

The length of A and B will be between 1 and 10000.

**Accepted**in 00:44:06

### Longest Univalue Path

Given a binary tree, find the length of the longest path where each node in the path has the same value. This path may or may not pass through the root.

**Note:** The length of path between two nodes is represented by the number of edges between them.

**Example 1:**

```
Input:
5
/ \
4 5
/ \ \
1 1 5
Output: 2
```

**Example 2:**

```
Input:
1
/ \
4 5
/ \ \
4 4 5
Output: 2
```

**Note:** The given binary tree has not more than 10000 nodes. The height of the tree is not more than 1000.

**Accepted**in 01:25:38 with 1 wrong submissions

### Knight Probability in Chessboard

On an `N`

x`N`

chessboard, a knight starts at the `r`

-th row and `c`

-th column and attempts to make exactly `K`

moves. The rows and columns are 0 indexed, so the top-left square is `(0, 0)`

, and the bottom-right square is `(N-1, N-1)`

.

A chess knight has 8 possible moves it can make, as illustrated below. Each move is two squares in a cardinal direction, then one square in an orthogonal direction.

```
| | | | | |
--+---+---+---+---+---+--
| | # <---> # | |
--+---+---+ ^ +---+---+--
| # | | | | | # |
--+ ^ +---+ | +---+ ^ +--
| |<------@------>| |
--+ v +---+ | +---+ v +--
| # | | | | | # |
--+---+---+ v +---+---+--
| | # <---> # | |
--+---+---+---+---+---+--
| | | | | |
```

Each time the knight is to move, it chooses one of eight possible moves uniformly at random (even if the piece would go off the chessboard) and moves there.

The knight continues moving until it has made exactly `K`

moves or has moved off the chessboard. Return the probability that the knight remains on the board after it has stopped moving.

**Example:**

```
Input: 3, 2, 0, 0
Output: 0.0625
Explanation: There are two moves (to (1,2), (2,1)) that will keep the knight on the board.
From each of those positions, there are also two moves that will keep the knight on the board.
The total probability the knight stays on the board is 0.0625.
```

**Note:**

`N`

will be between 1 and 25.`K`

will be between 0 and 100.- The knight always initially starts on the board.

**Accepted**in 01:03:41

### Maximum Sum of 3 Non-Overlapping Subarrays

In a given array `nums`

of positive integers, find three non-overlapping subarrays with maximum sum.

Each subarray will be of size `k`

, and we want to maximize the sum of all `3*k`

entries.

Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.

**Example:**

```
Input: [1,2,1,2,6,7,5,1], 2
Output: [0, 3, 5]
Explanation: Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].
We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.
```

**Note:**

`nums.length`

will be between 1 and 20000.`nums[i]`

will be between 1 and 65535.`k`

will be between 1 and floor(nums.length / 3).

**Unsolved**