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
Input: target = 7, nums = [2,3,1,2,4,3]
Explanation: The subarray [4,3] has the minimal length under the problem constraint.
Input: target = 4, nums = [1,4,4]
Input: target = 11, nums = [1,1,1,1,1,1,1,1]
1 <= target <= 109
1 <= nums.length…
Given two strings
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.
Input: s = "ab#c", t = "ad#c"
Explanation: Both s and t become "ac".
Input: s = "ab##", t = "c#d#"
Explanation: Both s and t become "".
Input: s = "a##c", t = "#a#c"
Explanation: Both s and t become "c".
Input: s = "a#c", t =…
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
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
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…
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
keysPressed[i] was the
ith key pressed in the testing sequence, and a sorted list
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
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
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
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.
Input: nums = [0,1,0,3,12]
Input: nums = 
1 <= nums.length <= 104
-231 <= nums[i] <= 231 - 1
Follow up: Could you minimize the total number of operations done?
Given an integer
n, return all the structurally unique BST's (binary search trees), which has exactly
n nodes of unique values from
n. Return the answer in any order.
Input: n = 3
Input: n = 1
1 <= n <= 8
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.
void checkIn(int id, string stationName, int t)
id, checks in at the station
void checkOut(int id, string stationName, int t)
id, checks out from the station
Given a non-negative integer
c, decide whether there're two integers
b such that
a2 + b2 = c.
Input: c = 5
Explanation: 1 * 1 + 2 * 2 = 5
Input: c = 3
Input: c = 4
Input: c = 2
Input: c = 1
0 <= c <= 231 - 1
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.
arr = [2,3,4], the median is
arr = [2,3], the median is
(2 + 3) / 2 = 2.5.
Implement the MedianFinder class:
void addNum(int num)adds the integer
numfrom the data stream to the data structure.
double findMedian()returns the median of all elements so far. …