Leetcode 680: Valid Palindrome II
The original question can be found here. The question is asking if a string is palindromic if at most 1 character can be removed from string. Let’s look at an example: Let’s say we still use the 2 pointers apporach…
The original question can be found here. The question is asking if a string is palindromic if at most 1 character can be removed from string. Let’s look at an example: Let’s say we still use the 2 pointers apporach…
The original question can be found here. The question is asking for a given string, determine if it’s palindromic. Only alphanumeric letters are taking into account and letters’ cases are ignored. Reverse and Compare The first solution we can think…
The original question can be found here. There’re multiple solutions to this question, and we’ll start with the brute force one. Brute Force We enumerate all substrings and check if it’s palindromic. If yes, we update the final result by…
Here are some interview skills and coding styles that on top of my head. Interview Skills Try to avoid “I know a fancy algorithm called xyz…” Try to avoid using uncommon existing algorithms used for very specific cases, such as…
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…