Skip to main content
59, Spiral Matrix II

I Problem

Given a positive integer n, generate an n x n matrix filled with elements from 1 to n² in spiral order.

Example 1:

Input: n = 3
Output: [[1, 2, 3], [8, 9, 4], [7, 6, 5]]

Example 2:
Input: n = 1
Output: [[1]]


MikeAbout 2 minarraymediumarraymatrixsimulation
54, Spiral Matrix

I Problem

Given an m x n matrix, return all elements of the matrix in spiral order.

Example 1

Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Output: [1, 2, 3, 6, 9, 8, 7, 4, 5]

Example 2

Input: matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
Output: [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7]


MikeAbout 2 minarraymediumarraymatrixsimulation
76, Minimum Window Substring

I Problem

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".

The testcases will be generated such that the answer is unique.


MikeAbout 2 minarrayhardhash tablestringsliding window
904, Fruit Into Baskets

I Problem

You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array fruits where fruits[i] is the type of fruit the iᵗʰ tree produces.

You want to collect as much fruit as possible. However, the owner has some strict rules that you must follow:


MikeAbout 2 minarraymediumarrayhash tablesliding window
209, Minimum Size Subarray Sum

I Problem

Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose 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: 2
Explanation: The subarray [4,3] has the minimal length under the problem constraint.


MikeAbout 2 minarraymediumarraybinary searchsliding windowprefix sum
27, Remove Element

I Problem

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.

Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:


MikeAbout 1 minarrayeasyarraytwo pointers
704, Binary Search

I Problem

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums.
If target exists, then return its index. Otherwise, return -1.

You must write an algorithm with O(log n) runtime complexity.

Example 1:
Input: nums = [-1,0,3,5,9,12], target = 9
Output: 4
Explanation: 9 exists in nums and its index is 4


MikeAbout 2 minarrayeasyarraybinary search
977, Squares of a Sorted Array

I Problem

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

Example 1:
Input: nums = [-4, -1, 0, 3, 10]
Output: [0, 1, 9, 16, 100]
Explanation: After squaring, the array becomes [16, 1, 0, 9, 100]. After sorting, it becomes [0, 1, 9, 16, 100].


MikeAbout 2 minarrayeasyarraytwo pointerssorting
844, Backspace String Compare

I Problem

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: true
Explanation: Both s and t become "ac".


MikeAbout 2 minarrayeasyarraytwo pointersstackstring
283, Move Zeroes

I Problem

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]


MikeAbout 1 minarrayeasyarraytwo pointers
2