# LeetCode Weekly Contest 133

https://leetcode.com/contest/weekly-contest-133

## Matrix Cells in Distance Order

We are given a matrix with R rows and C columns has cells with integer coordinates (r, c), where 0 <= r < R and 0 <= c < C.

Additionally, we are given a cell in that matrix with coordinates (r0, c0).

Return the coordinates of all cells in the matrix, sorted by their distance from (r0, c0) from smallest distance to largest distance. Here, the distance between two cells (r1, c1) and (r2, c2) is the Manhattan distance, |r1 - r2| + |c1 - c2|. (You may return the answer in any order that satisfies this condition.)

Example 1:

Example 2:

Example 3:

Note:

1. 1 <= R <= 100
2. 1 <= C <= 100
3. 0 <= r0 < R
4. 0 <= c0 < C

## Two City Scheduling

There are 2N people a company is planning to interview. The cost of flying the i-th person to city A is costs[i], and the cost of flying the i-th person to city B is costs[i].

Return the minimum cost to fly every person to a city such that exactly N people arrive in each city.

Example 1:

Note:

1. 1 <= costs.length <= 100
2. It is guaranteed that costs.length is even.
3. 1 <= costs[i], costs[i] <= 1000

## Maximum Sum of Two Non-Overlapping Subarrays

Given an array A of non-negative integers, return the maximum sum of elements in two non-overlapping (contiguous) subarrays, which have lengths L and M. (For clarification, the L-length subarray could occur before or after the M-length subarray.)

Formally, return the largest V for which V = (A[i] + A[i+1] + ... + A[i+L-1]) + (A[j] + A[j+1] + ... + A[j+M-1]) and either:

1. 0 <= i < i + L - 1 < j < j + M - 1 < A.length, or
2. 0 <= j < j + M - 1 < i < i + L - 1 < A.length.

Example 1:

Example 2:

Example 3:

Note:

1. L >= 1
2. M >= 1
3. L + M <= A.length <= 1000
4. 0 <= A[i] <= 1000

## Stream of Characters

Implement the StreamChecker class as follows:

• StreamChecker(words): Constructor, init the data structure with the given words.
• query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, including this letter just queried) spell one of the words in the given list.

Example:

Note:

1. 1 <= words.length <= 2000
2. 1 <= words[i].length <= 2000
3. Words will only consist of lowercase English letters.
4. Queries will only consist of lowercase English letters.
5. The number of queries is at most 40000.