You are given an n x n 2D
Continue reading “[Leetcode]48. Rotate Image”
matrix representing an image, rotate the image by 90 degrees (clockwise).
You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
Given a list of daily temperatures
Continue reading “[Leetcode]739. Daily Temperatures”
T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put
For example, given the list of temperatures
T = [73, 74, 75, 71, 69, 72, 76, 73], your output should be
[1, 1, 4, 2, 1, 1, 0, 0].
Note: The length of
temperatures will be in the range
[1, 30000]. Each temperature will be an integer in the range
Continue reading “[Leetcode]835. Image Overlap”
B are given, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)
We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top of the other image. After, the overlap of this translation is the number of positions that have a 1 in both images.
(Note also that a translation does not include any kind of rotation.)
What is the largest possible overlap?
1 <= A.length = A.length = B.length = B.length <= 30
0 <= A[i][j], B[i][j] <= 1
Given an array
Continue reading “[Leetcode]283. Move Zeroes”
nums, write a function to move all
0's to the end of it while maintaining the relative order of the non-zero elements.
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).
The replacement must be in-place and use only constant extra memory.
Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.
Continue reading “[Leetcode]31. Next Permutation”
Given an array
Continue reading “[Leetcode]238. Product of Array Except Self”
nums of n integers where n > 1, return an array
output such that
output[i] is equal to the product of all the elements of
Note: Please solve it without division and in O(n).
Could you solve it with constant space complexity? (The output array does not count as extra space for the purpose of space complexity analysis.)
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
Find all the elements that appear twice in this array.
Could you do it without extra space and in O(n) runtime?
Continue reading “[Leetcode]442. Find All Duplicates in an Array”
Given the array
Continue reading “[Leetcode]1508. Range Sum of Sorted Subarray Sums”
nums consisting of
n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, creating a new array of
n * (n + 1) / 2 numbers.
Return the sum of the numbers from index
left to index
right (indexed from 1), inclusive, in the new array. Since the answer can be a huge number return it modulo 10^9 + 7.