# Leetcode 209. Minimum Size Subarray Sum

[medium]

Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a contiguous subarray `[numsl, numsl+1, ..., numsr-1, numsr]` of which the sum is greater than or equal to `target`. If there is no such subarray, return `0` instead.

Example 1:

`Input: target = 7, nums = [2,3,1,2,4,3]Output: 2Explanation: The subarray [4,3] has the minimal length under the problem constraint.`

Example 2:

`Input: target = 4, nums = [1,4,4]Output: 1`

Example 3:

`Input: target = 11, nums = [1,1,1,1,1,1,1,1]Output: 0`

Constraints:

• `1 <= target <= 109`
• `1 <= nums.length…`

# Leetcode 844. Backspace String Compare

[easy][IBM]

Given two strings `s` and `t`, return `true` if they are equal when both are typed into empty text editors. `'#'` means a backspace character.

Note that after backspacing an empty text, the text will continue empty.

Example 1:

`Input: s = "ab#c", t = "ad#c"Output: trueExplanation: Both s and t become "ac".`

Example 2:

`Input: s = "ab##", t = "c#d#"Output: trueExplanation: Both s and t become "".`

Example 3:

`Input: s = "a##c", t = "#a#c"Output: trueExplanation: Both s and t become "c".`

Example 4:

`Input: s = "a#c", t =…`

# Leetcode 764. Largest Plus Sign

[medium]

You are given an integer `n`. You have an `n x n` binary grid `grid` with all values initially `1`'s except for some indices given in the array `mines`. The `ith` element of the array `mines` is defined as `mines[i] = [xi, yi]` where `grid[xi][yi] == 0`.

Return the order of the largest axis-aligned plus sign of 1’s contained in `grid`. If there is none, return `0`.

An axis-aligned plus sign of `1`'s of order `k` has some center `grid[r][c] == 1` along with four arms of length `k - 1` going up, down, left, and right, and made…

# Leetcode 1629. Slowest Key

[easy]

A newly designed keypad was tested, where a tester pressed a sequence of `n` keys, one at a time.

You are given a string `keysPressed` of length `n`, where `keysPressed[i]` was the `ith` key pressed in the testing sequence, and a sorted list `releaseTimes`, where `releaseTimes[i]` was the time the `ith` key was released. Both arrays are 0-indexed. The `0th` key was pressed at the time `0`, and every subsequent key was pressed at the exact time the previous key was released.

The tester wants to know the key of the keypress that had the longest duration. The `ith`

# Leetcode 1028. Recover a Tree From Preorder Traversal

[hard]

We run a preorder depth-first search (DFS) on the `root` of a binary tree.

At each node in this traversal, we output `D` dashes (where `D` is the depth of this node), then we output the value of this node. If the depth of a node is `D`, the depth of its immediate child is `D + 1`. The depth of the `root` node is `0`.

If a node has only one child, that child is guaranteed to be the left child.

Given the output `traversal` of this traversal, recover the tree and return its `root`.

Example 1:

`Input…`

# Leetcode 283. Move Zeroes

[easy]

Given an integer array `nums`, move all `0`'s to the end of it while maintaining the relative order of the non-zero elements.

Note that you must do this in-place without making a copy of the array.

Example 1:

`Input: nums = [0,1,0,3,12]Output: [1,3,12,0,0]`

Example 2:

`Input: nums = [0]Output: [0]`

Constraints:

• `1 <= nums.length <= 104`
• `-231 <= nums[i] <= 231 - 1`

Follow up: Could you minimize the total number of operations done?

[Java-Gary]

1. if we don’t want to copy the another array, I will add another variable to track how many zeros we have
2. During…

# Leetcode 95. Unique Binary Search Trees II

[medium]

Given an integer `n`, return all the structurally unique BST's (binary search trees), which has exactly `n` nodes of unique values from `1` to `n`. Return the answer in any order.

Example 1:

`Input: n = 3Output: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]`

Example 2:

`Input: n = 1Output: [[1]]`

Constraints:

• `1 <= n <= 8`

[Java]

1. Think: will need a arraylist for the answer(TreeNode in the list)
2. will need to use recursive to do the in-order traversal
3. generate left subtree and right subtree, add them with the root, and recursive multiple situation.
4. Trick: left = genTrees(start, i-1), right = genTrees(i+1, end)

# Leetcode 1396. Design Underground System

[medium]

An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another.

Implement the `UndergroundSystem` class:

• `void checkIn(int id, string stationName, int t)`
• A customer with a card ID equal to `id`, checks in at the station `stationName` at time `t`.
• A customer can only be checked into one place at a time.
• `void checkOut(int id, string stationName, int t)`
• A customer with a card ID equal to `id`, checks out from the station `stationName` at time `t`.
• `…`

# Leetcode 633. Sum of Square Numbers

[medium]

Given a non-negative integer `c`, decide whether there're two integers `a` and `b` such that `a2 + b2 = c`.

Example 1:

`Input: c = 5Output: trueExplanation: 1 * 1 + 2 * 2 = 5`

Example 2:

`Input: c = 3Output: false`

Example 3:

`Input: c = 4Output: true`

Example 4:

`Input: c = 2Output: true`

Example 5:

`Input: c = 1Output: true`

Constraints:

• `0 <= c <= 231 - 1`

[Java]

1. use two pointer to closer the target number
2. if we could not find a result for the nunmber c, return false

# Leetcode 295. Find Median from Data Stream

[hard]

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values.

• For example, for `arr = [2,3,4]`, the median is `3`.
• For example, for `arr = [2,3]`, the median is `(2 + 3) / 2 = 2.5`.

Implement the MedianFinder class:

• `MedianFinder()` initializes the `MedianFinder` object.
• `void addNum(int num)` adds the integer `num` from the data stream to the data structure.
• `double findMedian()` returns the median of all elements so far. …

## Gary Chiang

CS new grad, 6 years experience related to supply chain management. Located in Bay area

Get the Medium app