You are given anContinue reading “[Leetcode]48. Rotate Image”nxn2D`matrix`

representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the imagein-place, which means you have to modify the input 2D matrix directly.DO NOTallocate another 2D matrix and do the rotation.

## [Leetcode]739. Daily Temperatures

Given a list of daily temperaturesContinue 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`0`

instead. 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`[30, 100]`

.

## [Leetcode]835. Image Overlap

Two imagesContinue reading “[Leetcode]835. Image Overlap”`A`

and`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, theoverlapof this translation is the number of positions that have a 1 in both images. (Note also that a translation doesnotinclude any kind of rotation.) What is the largest possible overlap?Notes:`1 <= A.length = A[0].length = B.length = B[0].length <= 30`

`0 <= A[i][j], B[i][j] <= 1`

## [Leetcode]283. Move Zeroes

Given an arrayContinue 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.Note: You must do thisin-placewithout making a copy of the array. Minimize the total number of operations.

## [Leetcode]31. Next Permutation

ImplementContinue reading “[Leetcode]31. Next Permutation”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 bein-placeand 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.`1,2,3`

→`1,3,2`

`3,2,1`

→`1,2,3`

`1,1,5`

→`1,5,1`

## [Leetcode]238. Product of Array Except Self

Given an arrayContinue reading “[Leetcode]238. Product of Array Except Self”`nums`

ofnintegers wheren> 1, return an array`output`

such that`output[i]`

is equal to the product of all the elements of`nums`

except`nums[i]`

.Note:Please solve itwithout divisionand in O(n).Follow up:Could you solve it with constant space complexity? (The output arraydoes notcount as extra space for the purpose of space complexity analysis.)Example:Input:`[1,2,3,4]`

Output:`[24,12,8,6]`

## [Leetcode]442. Find All Duplicates in an Array

Given an array of integers, 1 ≤ a[i] ≤Continue reading “[Leetcode]442. Find All Duplicates in an Array”n(n= size of array), some elements appeartwiceand others appearonce. Find all the elements that appeartwicein this array. Could you do it without extra space and in O(n) runtime?

## [Leetcode]1508. Range Sum of Sorted Subarray Sums

Given the arrayContinue 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.