Leetcode 4: Median of Two Sorted Arrays
The original question can be found here. The question is asking to return the median number of 2 sorted arrays. Let’s say array nums1‘s length is m and nums2‘s length is n. If the sum of m and n is…
The original question can be found here. The question is asking to return the median number of 2 sorted arrays. Let’s say array nums1‘s length is m and nums2‘s length is n. If the sum of m and n is…
The original question can be found here. The question is aksing for the intersection of two arrays, and element in final result should be unique. There’re multiple solutions for this question. Hash Set Load one array into a hashset, and…
The original question can be found here. It’s asking us to merge array nums2 into array nums1. The most straightforward solution is: for each element inside array nums2, we insert into nums1 to find an appropriate position. Once we find…
The orignal question can be found here. The question is asking the number of subarrays which the sum value equals to K. The brute force solution is very straight forward. We simply enumerate all the possible subarrays to find out…
The original question can be found here. The question is aksing for the largest sum of the subarray. We can enumerate all possible subarrays and return the lagest sum. The time complexity is O(n^2)which is not quite acceptable. To find…
The original question can be found here. The question is asking to find the maximum number inside each sliding window(subarray). Brute Force Go through each subarray and find the maximum value. The time complexity is O(n*k), where n is the…
Prefix sum is a very useful technique which can be used for some subarray questions. Let’s look at how it works. PrefixSum[i] stands for the sum of first i elements, which means the sum from array[0] to array[i – 1].…
The original question can be found here. This question is quite tricky. I will say best of luck to you if this is the first time you see this question during a real interview. I’ll skip the brute force solution…