# Algorithm problem list ## level 1 easy - https://leetcode.com/problems/check-if-n-and-its-double-exist/ - hash table =>T: O(N), S: O(N) - binary search => T: O(NlogN), S: O(1) - corner case: value 0 - non-unique value :::info - Test case ```go= Given an integer array A, write a function to check if there exists different index i and j such that A[i] = 2*A[j] if exist such pair, return true otherwise, return false [10,2,5,3] [10,2,0,0,5,3] [-2,-1,0,1,3] ``` ::: - 單敗淘汰賽, 比出冠軍最少需要多少場, 可不fair - O(logN) => divide+remain 計算 - O(1) => N-1 ![](https://i.imgur.com/E97zupw.png) - https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/ - hash table - https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/ - sum of difference of two adjacent values - https://leetcode.com/problems/best-meeting-point/ - 1維版本 - naive solution O(N^2) - opt solution O(N) - follow up, 2維版本 (level 3-4) - [1,0,1,0,0,0,1,0,1] => answer = 12 - follow up, 可容納多個人情況 - [3,0,2,1,3,0,2,0,3] ## level 2 - https://leetcode.com/problems/satisfiability-of-equality-equations/ - union find ```go= Input: ["a==b","b!=a"] Input: ["b==a","a==b"] Input: ["a==b","c!=a", "a==d", "c!=d"] Input: ["a==b","b==c", "c!=a"] label = 1000 equation = 1e5 ``` - https://leetcode.com/problems/tuple-with-same-product/ - hast table + math - https://leetcode.com/problems/max-consecutive-ones-iii - two pointer - O(N) - binary search - O(NlogN) - https://codeforces.com/contest/1625/problem/A - 思考題 - bitwise operation ```go= Given an integer array A, write a function to find a interger X (may not in A) 1. X has minimum sum of Hamming distance to all other elements in array 2. X is as small as possible Hamming distance is the number of positions at which the corresponding bits are different. 18 9 21 ans = 17 10010 01001 10101 answer 10001 ``` ## level 3 - https://leetcode.com/problems/maximum-subarray-min-product/ - prev smaller + next smaller + range sum - the same as max [histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) - https://leetcode.com/problems/largest-submatrix-with-rearrangements/ - rolling rectangle area - O(M\*N) - https://leetcode.com/problems/longest-string-chain/ - dfs + dp ```go= ["a","b","ba","bca","bda","bdca"] ["a","ba","bda","bdca"] 1 <= words.length <= 1000 1 <= words[i].length <= 16 words[i] only consists of lowercase English letters. ``` ## level 4