less than 0), we do something similar. Sort index by value, then transfer problem into finding max gap between index, O(nlogn) and O(1), 1. ♥ means you need a subscription. Easy. Recursively DFS with root.left.left and root.left.right check. Work fast with our official CLI. Each move is equal to minus one element in array, so the answer is the sum of all elements after minus min. and O(n!! Then, the remain index with positive values are result. Get the len and check left and right with 10^len, 10, Add all curr, if curr > prev, then need to subtract 2 * prev, 1. And remember…, How to Create a .Exe of Your Project From the Command Prompt, Organizing Yourself as an Indie Developer, How to Generate Leads with Web Scraping in Python, These are the best free courses to help you learn Java 8 and Java 9. Learn more, We use analytics cookies to understand how you use our websites so we can make them better, e.g. After a break, I started teaching myself more of Python by taking on data structure and algorithms questions on Leetcode. 1. Recursively brute force, O(n) and O(n), Careful about corner cases, such 1-20 and 21-Hundred, O(lgn) and O(1), ways[i>2] = (ways[i-1] + ways[i-2]) * (k - 1), O(n) and O(1), 1. 1. Check the different position and conditions, Add -1 to lower for special case, then check if curr - prev >= 2, 1. fix-sized queue or dequeue, O(1) and O(n), 1. hash which stores the latest timestamp, O(1) and O(n), 1. Two Sum IV - Input is a BST. Overflow when the result is greater than 2147483647 or less than -2147483648. Be careful about key conflict and key remove. Set or hash to check leaft, O(n^2) and O(n), Sort and generate x subset with previous results, O(n^2) and O(n^2), 1. DFS with swapping, check duplicate, O(n^2) and O(n^2), 1. Sort and find mean, O(mnlogmn) and O(1), Bottom-up or top-down recursion, O(n) and O(n), Quick union find with weights, O(nlogn) and O(n), Bottom-up or top-down DP, dp[n] = min(dp[n], dp[n - v_i]), where v_i is the coin, O(amount * n) and O(amount), 1. Bottom-up DP, dp[i][j] = dmap[i-1][j] + dmap[i][j-1], O(mn) and O(mn), Bottom-up DP, dp[i][j] = dmap[i-1][j] + dmap[i][j-1] (if block, then 0), O(mn) and O(mn), 1. strip leading and tailing space, then check float using exception, check e using split, Bottom-up DP, dp[i] = dp[i - 2] + dp[i- 1], 1. Two Sum Less Than K. Easy. Reduce to two sum smaller, then binary search, O(n^2lgn) and O(1), Compute frequency, check number of odd occurrences <= 1 then palindrome, O(n) and O(n), 1. Top-down O(n^2) and O(n), Bottom-up recursion with sentinel -1 O(n) and O(n), 1. O(n) and O(1), Queue, remove val in head when val < t - 3000, O(n) and O(n), Sort, then list duplicate and missing value in sorted list. If nothing happens, download the GitHub extension for Visual Studio and try again. Better solution is that reverse can be O(1) space in array. Except we have to account for that “-” symbol. Sort and insert (n - 1) / 2 from tail to correct position, O(nlogn) and O(1), 1. Sort and O(n^2) search with three points, The same as 3Sum, but we can merge pairs with the same sum, 1. For more information, see our Privacy Statement. 4Sum. Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world. Store index and check, O(logn) and O(logn), DFS (stack or recursion) get leaf value sequence and compare, O(n) and O(n), 1. It’s an edge-case we’ll have to deal with a little later. Python and Java full list. Below is the full code: This I think is a readable, easy to follow solution. Further, they’re hard to read and interpret what’s going on. “Am I going viral?” An AWS Data Engineering project. … Any questions? Handle each 2k until reaching end, On(n) and O(n). Show More . We can twice for left and right (reverse), O(n) and O(n), Update index1 and index2, and check distance, O(n) and O(1), Hash table and reverse string, O(n) and O(n), Hash and generate hash code for each string, O(n) and O(n), 1. That’s what this part does: If we don’t meet this condition, then our result variable already has the right answer, and we should just return it in line 12.