LeetCode 153 - Find the minimum element in a sorted and rotated array


Related: LeetCode 154 - Find Minimum in Rotated Sorted Array II
Find the minimum element in a sorted and rotated array - GeeksforGeeks
http://www.csdn123.com/html/topnews201408/84/5484.htm
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
You may assume no duplicate exists in the array.
X. Recursion
https://www.programcreek.com/2014/02/leetcode-find-minimum-in-rotated-sorted-array/
public int findMin(int[] num) {
 return findMin(num, 0, num.length - 1);
}
 
public int findMin(int[] num, int left, int right) {
 if (left == right)
  return num[left];
 if ((right - left) == 1)
  return Math.min(num[left], num[right]);
 
 int middle = left + (right - left) / 2;
 
 // not rotated
 if (num[left] < num[right]) {
  return num[left];
 
 // go right side
 } else if (num[middle] > num[left]) {
  return findMin(num, middle, right);
 
 // go left side
 } else {
  return findMin(num, left, middle);
 }
}

X. 
    int findMin(vector<int> &num) {
        int low = 0, high = num.size() - 1;
        // loop invariant: 1. low < high
        //                 2. mid != high and thus A[mid] != A[high] (no duplicate exists)
        //                 3. minimum is between [low, high]
        // The proof that the loop will exit: after each iteration either the 'high' decreases
        // or the 'low' increases, so the interval [low, high] will always shrink.
        while (low < high) {
            auto mid = low + (high - low) / 2;
            if (num[mid] < num[high])
                // the mininum is in the left part
                high = mid;
            else if (num[mid] > num[high])
                // the mininum is in the right part
                low = mid + 1;
        }

        return num[low];
    }
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/discuss/48589/9-line-java-code-beats-95.14-run-times
  public int findMin(int[] nums) {
    int low = 0, high = nums.length - 1;
    while (low < high) {
      int mid = low + (high - low) / 2;
      if (nums[mid] > nums[high]) {
        low = mid + 1;
      } else {
        high = mid;
      }
    }
    return nums[low];
  }

public int findMin(int[] nums) {
    if(nums==null || nums.length==0)
        return -1;
 
    int i=0; 
    int j=nums.length-1;
 
    while(i<=j){
        if(nums[i]<=nums[j])
            return nums[i];
 
        int m=(i+j)/2;
 
        if(nums[m]>=nums[i]){
            i=m+1;
        }else{
            j=m;
        }
    }
 
    return -1;
}
https://leetcode.com/articles/find-minimum-in-rotated-sorted-array/
    // If the list has just one element then return that element.
    if (nums.length == 1) {
      return nums[0];
    }

    // initializing left and right pointers.
    int left = 0, right = nums.length - 1;

    // if the last element is greater than the first element then there is no
    // rotation.
    // e.g. 1 < 2 < 3 < 4 < 5 < 7. Already sorted array.
    // Hence the smallest element is first element. A[0]
    if (nums[right] > nums[0]) {
      return nums[0];
    }

    // Binary search way
    while (right >= left) {
      // Find the mid element
      int mid = left + (right - left) / 2;

      // if the mid element is greater than its next element then mid+1 element is the
      // smallest
      // This point would be the point of change. From higher to lower value.
      if (nums[mid] > nums[mid + 1]) {
        return nums[mid + 1];
      }

      // if the mid element is lesser than its previous element then mid element is
      // the smallest
      if (nums[mid - 1] > nums[mid]) {
        return nums[mid];
      }

      // if the mid elements value is greater than the 0th element this means
      // the least value is still somewhere to the right as we are still dealing with
      // elements
      // greater than nums[0]
      if (nums[mid] > nums[0]) {
        left = mid + 1;
      } else {
        // if nums[0] is greater than the mid value then this means the smallest value
        // is somewhere to
        // the left
        right = mid - 1;
      }
    }
    return -1;
  }

http://www.cnblogs.com/zuoyuan/p/4045742.html
下图是这道题的数组的两种情况,分别去处理就可以了

http://www.bijishequ.com/detail/134759?p=66
Hint: 二分查找的精髓就在于不断Shrink区间,最后锁定目标值的位置,这也是它的循环不变量。对于这道题来说,关键就在于确定最小值在左还是在右。这并不难,如果发现右半部分是有序的(判断左半部分有序是没用的,最小值既可能是第一个也可能因为旋转在右半部分),则这些值都可以排除掉,只有中点和前半部分的数有可能是最小值,所以就去前半部分继续查找就行了。否则的话则右半部分是乱序,说明最小值在其中。因为每次Shrink区间时不一定会缩小,容易死循环。
https://leetcode.com/discuss/32675/very-simple-java-binary-search
public int searchMinRotatedArray(int[] array, int start ,int end){ if(start == end) return array[start]; int mid = (start+end)/2; if(array[mid] < array[end]) return searchMinRotatedArray(array, start, mid); else return searchMinRotatedArray(array, mid+1, end); }
https://discuss.leetcode.com/topic/6112/a-concise-solution-with-proof-in-the-comment/
    int findMin(vector<int> &num) {
        int low = 0, high = num.size() - 1;
        // loop invariant: 1. low < high
        //                 2. mid != high and thus A[mid] != A[high] (no duplicate exists)
        //                 3. minimum is between [low, high]
        // The proof that the loop will exit: after each iteration either the 'high' decreases
        // or the 'low' increases, so the interval [low, high] will always shrink.
        while (low < high) {
            auto mid = low + (high - low) / 2;
            if (num[mid] < num[high])
                // the mininum is in the left part
                high = mid;
            else if (num[mid] > num[high])
                // the mininum is in the right part
                low = mid + 1;
        }

        return num[low];
    }
https://leetcode.com/discuss/81444/9-line-java-code-beats-95-14%25-run-times
if the array is indeed rotated by some pivot, there are only 2 possibilities
  1. a[mid] > a[left] && a[mid] > a[right], meaning we are on the bigger part, the smaller part is on our right, so go right
  2. a[mid] < a[left] && a[mid] < a[right], meaning we are on the smaller part, to find the smallest element, go left
if the array is not rotated (actually one rotating cycle completed), we just need to go left, in this case a[mid] < a[right] always holds.
combining the cases above, we conclude that
if a[mid] > a[right], go right; if a[mid] < a[right], go left.
public int findMin(int[] nums) { if (nums==null || nums.length==0) { return Integer.MIN_VALUE; } int left = 0, right = nums.length-1; while (left < right-1) { // while (left < right-1) is a useful technique int mid = left + (right-left)/2; if (nums[mid] > nums[right]) { left = mid; } else { right = mid; } } if (nums[left] > nums[right]) { return nums[right]; } return nums[left]; }
http://bangbingsyb.blogspot.com/2014/11/leecode-find-minimum-in-rotated-sorted.html
Search in Rotated Sorted Array I这题换汤不换药。同样可以根据A[mid]和A[end]来判断右半数组是否sorted:
原数组:0 1 2 4 5 6 7
情况1:  6 7 0 1 2 4 5   
情况2:  2 4 5 6 7 0 1  
(1) A[mid] < A[end]:A[mid : end] sorted => min不在A[mid+1 : end]中
搜索A[start : mid]
(2) A[mid] > A[end]:A[start : mid] sorted且又因为该情况下A[end]<A[start] => min不在A[start : mid]中
搜索A[mid+1 : end]
(3) base case:
a. start =  end,必然A[start]为min,为搜寻结束条件。
b. start + 1 = end,此时A[mid] =  A[start],而min = min(A[mid], A[end])。而这个条件可以合并到(1)和(2)中。
    int findMin(vector<int> &num) {
        int start = 0, end = num.size()-1;
        while(start<end) {//\\
            int mid = start+(end-start)/2;
            if(num[mid]<num[end]) 
                end = mid;//\\
            else 
                start = mid+1;
        }
        return num[start];
    }

http://www.cnblogs.com/springfor/p/4217615.html
首先假设一个sorted没有rotated的数组[1,2,3],假设我们通过一个pivot把这个数组rotate,那么结果可能为:[2,3,1], [3,1,2], 可以发现:num[low]永远大于(或等于)num[high]。因为你之前是sorted的数组,你在一个sorted的数组找了一个pivot进行rotate,那么比如pivot后面的值都大于pivot之前的值。所以依据这个发现,以及二分法查找。我们可以根据以下判断来解题。num[mid]有两种可能性,如果num[mid] > num[high],证明num[mid]在rotated后的那个区间内,这个区间我们刚才已知都大于pivot之前的值,所以最小值就在low=mid+1那个区间内。另一种可能,num[mid] <= num[high],那么我们刚才可以看出来这种可能性说明mid~high以及是排好序的,那么最小值在high=mid这个区间内(mid可能是最小值)。依据此判断可以找到最小值。
 1     public int findMin(int[] num) {
 2         int low = 0, high = num.length - 1;
 3         while (low < high && num[low] >= num[high]) {
 4             int mid = (low + high) / 2;
 5             if (num[mid] > num[high])
 6                 low = mid + 1;
 7             else
 8                 high = mid;
 9         }
10         return num[low];
11     }
http://blog.csdn.net/linhuanmars/article/details/20525681
  1. public int findMin(int[] num) {  
  2.     if(num == null || num.length==0)  
  3.         return 0;  
  4.     int l = 0;  
  5.     int r = num.length-1;  
  6.     int min = num[0];  
  7.     while(l<r-1)  
  8.     {  
  9.         int m = (l+r)/2;  
  10.         if(num[l]<num[m])  
  11.         {  
  12.             min = Math.min(num[l],min);  
  13.             l = m+1;  
  14.         }  
  15.         else if(num[l]>num[m])  
  16.         {  
  17.             min = Math.min(num[m],min);  
  18.             r = m-1;  
  19.         }  
  20.         else  
  21.         {  
  22.             l++;  
  23.         }  
  24.     }  
  25.     min = Math.min(num[r],min);  
  26.     min = Math.min(num[l],min);  
  27.     return min;  
  28. }  
public int FindMin(int[] nums) { int left = 0, right = nums.Length - 1, mid = 0; while(left < right){ mid = (left + right) >> 1; if(nums[mid] > nums[right]) left = mid + 1; else right = mid; } return nums[right]; }
I think both nums[right] and nums[left] should be OK in this case, because when breaking the while loop, "left" should be equal to "right".


    public int findMin(int[] nums) {
        if (nums == null || nums.length == 0) {
            return -1;
        }
        
        int start = 0, end = nums.length - 1;
        int target = nums[nums.length - 1];
        
        // find the first element <= target
        while (start + 1 < end) {
            int mid = start + (end - start) / 2;
            if (nums[mid] <= target) {
                end = mid;
            } else {
                start = mid;
            }
        }
        if (nums[start] <= target) {
            return nums[start];
        } else {
            return nums[end];
        }
    }
X. https://discuss.leetcode.com/topic/5170/java-solution-with-binary-search
The minimum element must satisfy one of two conditions: 1) If rotate, A[min] < A[min - 1]; 2) If not, A[0]. Therefore, we can use binary search: check the middle element, if it is less than previous one, then it is minimum. If not, there are 2 conditions as well: If it is greater than both left and right element, then minimum element should be on its right, otherwise on its left.
    public int findMin(int[] num) {
        if (num == null || num.length == 0) {
            return 0;
        }
        if (num.length == 1) {
            return num[0];
        }
        int start = 0, end = num.length - 1;
        while (start < end) {
            int mid = (start + end) / 2;
            if (mid > 0 && num[mid] < num[mid - 1]) {
                return num[mid];
            }
            if (num[start] <= num[mid] && num[mid] > num[end]) {
                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        return num[start];
    }
X. Different way - not better
http://www.programcreek.com/2014/02/leetcode-find-minimum-in-rotated-sorted-array/
public int findMin(int[] num, int left, int right) {
 if (left == right)
  return num[left];
 if ((right - left) == 1)
  return Math.min(num[left], num[right]);
 
 int middle = left + (right - left) / 2;
 
 // not rotated
 if (num[left] < num[right]) {
  return num[left];
 
 // go right side
 } else if (num[middle] > num[left]) {
  return findMin(num, middle, right);
 
 // go left side
 } else {
  return findMin(num, left, middle);
 }
}
public int findMin(int[] nums) {
    if(nums.length==1)
        return nums[0];
 
    int left=0;
    int right=nums.length-1;
 
    //not rotated
    if(nums[left]<nums[right])
        return nums[left];
 
    while(left <= right){
        if(right-left==1){
            return nums[right];
        }
 
        int m = left + (right-left)/2;
 
        if(nums[m] > nums[right])
            left = m;
        else
            right = m;
    }
 
    return nums[left];
}
http://buttercola.blogspot.com/2015/08/leetcode-find-minimum-in-rotated-sorted.html
3 Compares in the loop.

    public int findMin(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
         
        int lo = 0;
        int hi = nums.length - 1;
         
        while (lo + 1 < hi) {
            int mid = lo + (hi - lo) / 2;
             
            if (nums[lo] < nums[hi]) {//
                return nums[lo];
            } else if (nums[mid] < nums[hi]) {
                hi = mid;
            } else if (nums[lo] < nums[mid]) {
                lo = mid;
            }
        }
         
        return Math.min(nums[lo], nums[hi]);
    }

How to handle duplicates?
It turned out that duplicates can’t be handled in O(Logn) time in all cases. Thanks to Amit Jain for inputs. The special cases that cause problems are like {2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 2} and {2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2}. It doesn’t look possible to go to left half or right half by doing constant number of comparisons at the middle. Following is an implementation that handles duplicates. It may become O(n) in worst case though.
http://www.csdn123.com/html/topnews201408/84/5484.htm
    public int findMin(int[] num) {
 3         if (num == null || num.length == 0) {
 4             return 0;
 5         }
 6         
 7         int len = num.length;
 8         if (len == 1) {
 9             return num[0];
10         } else if (len == 2) {
11             return Math.min(num[0], num[1]);
12         }
13         
14         int left = 0;
15         int right = len - 1;
16         
17         while (left < right - 1) {
18             int mid = left + (right - left) / 2;
19             // In this case, the array is sorted.
20             // 这一句很重要,因为我们移除一些元素后,可能会使整个数组变得有序...
21             if (num[left] < num[right]) {
22                 return num[left];
23             }
24             
25             // left side is sorted. CUT the left side.
26             if (num[mid] > num[left]) {
27                 left = mid;
28             // left side is unsorted, right side is sorted. CUT the right side.
29             } else if (num[mid] < num[left]) {
30                 right = mid;
31             } else {
32                 left++;
33             }
34         }
35         
36         return Math.min(num[left], num[right]);        
37     }
http://blog.csdn.net/linhuanmars/article/details/40449299
  1. public int findMin(int[] num) {  
  2.     if(num == null || num.length==0)  
  3.         return 0;  
  4.     int l = 0;  
  5.     int r = num.length-1;  
  6.     int min = num[0];  
  7.     while(l<r-1)  
  8.     {  
  9.         int m = (l+r)/2;  
  10.         if(num[l]<num[m])  
  11.         {  
  12.             min = Math.min(num[l],min);  
  13.             l = m+1;  
  14.         }  
  15.         else if(num[l]>num[m])  
  16.         {  
  17.             min = Math.min(num[m],min);  
  18.             r = m-1;  
  19.         }  
  20.         else  
  21.         {  
  22.             l++;  
  23.         }  
  24.     }  
  25.     min = Math.min(num[r],min);  
  26.     min = Math.min(num[l],min);  
  27.     return min;  
  28. }  
http://comproguide.blogspot.com/2014/03/how-many-times-sorted-array-is-rotated.html
Given a circularly sorted array of unique elements, how do we efficiently find the number of rotations?

For example the array [4, 5, 1, 2, 3] is (right) rotated twice.
int findRotations(const vector<int> &arr, int low, int high)
{
if( arr[low] <= arr[high] )
return low;
int len = arr.size();
int mid = (low + high) / 2;
int prev = (mid - 1 + len) % len; //if mid is at 0, consider last element as previous
int next = (mid + 1) % len; // if mid is the last element, consider next element as the first
 
if( arr[mid] < arr[prev] && arr[mid] < arr[next] )
return mid;
if( arr[low] <= arr[mid] ) // if left half is sorted, search in the right half
return findRotations(arr, mid+1, high);
else
return findRotations(arr, low, mid-1); // search in the right half
}
http://hehejun.blogspot.com/2015/01/algorithmfind-minimum-in-rotated-sorted.html
在原题Find Minimum in Rotated Sorted Array中,array的顺序是从小到大的。这次我们把array的顺序改成从大到小,解法会发生什么变化吗?通过这一题,我们会总结二分法边界条件的相关问题。
这一题的分析思路是和原题是一样的,同样为了代码的简洁我们比较A[lo]和A[mid]:
  • 如果A[mid] < A[lo],那么[lo, mid]是sorted的,minimum只可能在[mid, hi]区间里。
  • 如果A[mid] < A[lo],那么[mid, hi]不是sorted的,minimum只可能在[lo, mid)区间里。
所以如果A[mid] < A[lo],我们更新lo = mid;如果A[mid] < A[lo] 我们更新hi = mid - 1。但是随之而来的问题就是和原题不同,当我们把lo复制为mid的时候,当hi == lo  + 1的时候,二分就无法向下进行了,因为mid会一直等于lo。所以这个时候当hi <= lo + 1的时候我们就应该跳出,然后找lo和hi中较小的那一个。
分析到这里,我们可以看出,当二分的策略不同的时候,边界条件也是不同的,具体总结如下:
  • [lo, hi] -> [lo, mid) + (mid, hi],这个时候每次更新的时候lo = mid + 1,hi = mid - 1,跳出的条件至少应该是lo > hi
  • [lo, hi] -> [lo, mid] + (mid, hi],这个时候每次更新的时候lo = mid + 1,hi = mid,跳出的条件至少应该是lo >= hi,若条件为lo >= hi,跳出的时候情况为lo == hi
  • [lo, hi] -> [lo, mid) + [mid, hi],这个时候每次更新的时候lo = mid,hi = mid - 1,跳出的条件至少应该是lo + 1 >= hi,若条件为lo  + 1  >= hi,跳出的时候情况为lo == hi 或者 lo + 1 == hi
  • [lo, hi] -> [lo, mid) + (mid, hi],这个时候每次更新的时候lo = mid,hi = mid,跳出的条件至少应该是lo + 1 >= hi,若条件为lo  + 1  >= hi,跳出的时候情况为 lo + 1 == hi
    public int findMin(int[] num) {
        if (num == null)
            return -1;
        int len = num.length;
        int lo = 0, hi = len - 1;
        while (hi - lo > 1) {
            int mid = lo + (hi - lo) / 2;
            if (num[mid] < num[lo])
                lo = mid;
            else
                hi = mid - 1;
        }
        return num[lo] <= num[hi]? num[lo]: num[hi];
    }
https://leetcode.com/discuss/55773/java-solution-naive-and-optimized-method
O(N)
public int findMin(int[] nums) { int min = nums[0]; for(int i = 1; i < nums.length; i++){ if(min > nums[i]) min = nums[i]; } return min; }
http://bookshadow.com/weblog/2014/10/16/leetcode-find-minimum-rotated-sorted-array/
-- not good
def findMin(self, num): ans = num[0] size = len(num) low, high = 0, size - 1 while low <= high: mid = (low + high) / 2 if num[mid] <= num[high]: #min位于左侧上升沿 high = mid - 1 else: #min位于左侧上升沿与右侧上升沿之间 low = mid + 1 ans = min(ans, num[mid]) return ans
Read full article from Find the minimum element in a sorted and rotated array - GeeksforGeeks

Labels

LeetCode (1432) GeeksforGeeks (1122) LeetCode - Review (1067) Review (882) Algorithm (668) to-do (609) Classic Algorithm (270) Google Interview (237) Classic Interview (222) Dynamic Programming (220) DP (186) Bit Algorithms (145) POJ (141) Math (137) Tree (132) LeetCode - Phone (129) EPI (122) Cracking Coding Interview (119) DFS (115) Difficult Algorithm (115) Lintcode (115) Different Solutions (110) Smart Algorithm (104) Binary Search (96) BFS (91) HackerRank (90) Binary Tree (86) Hard (79) Two Pointers (78) Stack (76) Company-Facebook (75) BST (72) Graph Algorithm (72) Time Complexity (69) Greedy Algorithm (68) Interval (63) Company - Google (62) Geometry Algorithm (61) Interview Corner (61) LeetCode - Extended (61) Union-Find (60) Trie (58) Advanced Data Structure (56) List (56) Priority Queue (53) Codility (52) ComProGuide (50) LeetCode Hard (50) Matrix (50) Bisection (48) Segment Tree (48) Sliding Window (48) USACO (46) Space Optimization (45) Company-Airbnb (41) Greedy (41) Mathematical Algorithm (41) Tree - Post-Order (41) ACM-ICPC (40) Algorithm Interview (40) Data Structure Design (40) Graph (40) Backtracking (39) Data Structure (39) Jobdu (39) Random (39) Codeforces (38) Knapsack (38) LeetCode - DP (38) Recursive Algorithm (38) String Algorithm (38) TopCoder (38) Sort (37) Introduction to Algorithms (36) Pre-Sort (36) Beauty of Programming (35) Must Known (34) Binary Search Tree (33) Follow Up (33) prismoskills (33) Palindrome (32) Permutation (31) Array (30) Google Code Jam (30) HDU (30) Array O(N) (29) Logic Thinking (29) Monotonic Stack (29) Puzzles (29) Code - Detail (27) Company-Zenefits (27) Microsoft 100 - July (27) Queue (27) Binary Indexed Trees (26) TreeMap (26) to-do-must (26) 1point3acres (25) GeeksQuiz (25) Merge Sort (25) Reverse Thinking (25) hihocoder (25) Company - LinkedIn (24) Hash (24) High Frequency (24) Summary (24) Divide and Conquer (23) Proof (23) Game Theory (22) Topological Sort (22) Lintcode - Review (21) Tree - Modification (21) Algorithm Game (20) CareerCup (20) Company - Twitter (20) DFS + Review (20) DP - Relation (20) Brain Teaser (19) DP - Tree (19) Left and Right Array (19) O(N) (19) Sweep Line (19) UVA (19) DP - Bit Masking (18) LeetCode - Thinking (18) KMP (17) LeetCode - TODO (17) Probabilities (17) Simulation (17) String Search (17) Codercareer (16) Company-Uber (16) Iterator (16) Number (16) O(1) Space (16) Shortest Path (16) itint5 (16) DFS+Cache (15) Dijkstra (15) Euclidean GCD (15) Heap (15) LeetCode - Hard (15) Majority (15) Number Theory (15) Rolling Hash (15) Tree Traversal (15) Brute Force (14) Bucket Sort (14) DP - Knapsack (14) DP - Probability (14) Difficult (14) Fast Power Algorithm (14) Pattern (14) Prefix Sum (14) TreeSet (14) Algorithm Videos (13) Amazon Interview (13) Basic Algorithm (13) Codechef (13) Combination (13) Computational Geometry (13) DP - Digit (13) LCA (13) LeetCode - DFS (13) Linked List (13) Long Increasing Sequence(LIS) (13) Math-Divisible (13) Reservoir Sampling (13) mitbbs (13) Algorithm - How To (12) Company - Microsoft (12) DP - Interval (12) DP - Multiple Relation (12) DP - Relation Optimization (12) LeetCode - Classic (12) Level Order Traversal (12) Prime (12) Pruning (12) Reconstruct Tree (12) Thinking (12) X Sum (12) AOJ (11) Bit Mask (11) Company-Snapchat (11) DP - Space Optimization (11) Dequeue (11) Graph DFS (11) MinMax (11) Miscs (11) Princeton (11) Quick Sort (11) Stack - Tree (11) 尺取法 (11) 挑战程序设计竞赛 (11) Coin Change (10) DFS+Backtracking (10) Facebook Hacker Cup (10) Fast Slow Pointers (10) HackerRank Easy (10) Interval Tree (10) Limited Range (10) Matrix - Traverse (10) Monotone Queue (10) SPOJ (10) Starting Point (10) States (10) Stock (10) Theory (10) Tutorialhorizon (10) Kadane - Extended (9) Mathblog (9) Max-Min Flow (9) Maze (9) Median (9) O(32N) (9) Quick Select (9) Stack Overflow (9) System Design (9) Tree - Conversion (9) Use XOR (9) Book Notes (8) Company-Amazon (8) DFS+BFS (8) DP - States (8) Expression (8) Longest Common Subsequence(LCS) (8) One Pass (8) Quadtrees (8) Traversal Once (8) Trie - Suffix (8) 穷竭搜索 (8) Algorithm Problem List (7) All Sub (7) Catalan Number (7) Cycle (7) DP - Cases (7) Facebook Interview (7) Fibonacci Numbers (7) Flood fill (7) Game Nim (7) Graph BFS (7) HackerRank Difficult (7) Hackerearth (7) Inversion (7) Kadane’s Algorithm (7) Manacher (7) Morris Traversal (7) Multiple Data Structures (7) Normalized Key (7) O(XN) (7) Radix Sort (7) Recursion (7) Sampling (7) Suffix Array (7) Tech-Queries (7) Tree - Serialization (7) Tree DP (7) Trie - Bit (7) 蓝桥杯 (7) Algorithm - Brain Teaser (6) BFS - Priority Queue (6) BFS - Unusual (6) Classic Data Structure Impl (6) DP - 2D (6) DP - Monotone Queue (6) DP - Unusual (6) DP-Space Optimization (6) Dutch Flag (6) How To (6) Interviewstreet (6) Knapsack - MultiplePack (6) Local MinMax (6) MST (6) Minimum Spanning Tree (6) Number - Reach (6) Parentheses (6) Pre-Sum (6) Probability (6) Programming Pearls (6) Rabin-Karp (6) Reverse (6) Scan from right (6) Schedule (6) Stream (6) Subset Sum (6) TSP (6) Xpost (6) n00tc0d3r (6) reddit (6) AI (5) Abbreviation (5) Anagram (5) Art Of Programming-July (5) Assumption (5) Bellman Ford (5) Big Data (5) Code - Solid (5) Code Kata (5) Codility-lessons (5) Coding (5) Company - WMware (5) Convex Hull (5) Crazyforcode (5) DFS - Multiple (5) DFS+DP (5) DP - Multi-Dimension (5) DP-Multiple Relation (5) Eulerian Cycle (5) Graph - Unusual (5) Graph Cycle (5) Hash Strategy (5) Immutability (5) Java (5) LogN (5) Manhattan Distance (5) Matrix Chain Multiplication (5) N Queens (5) Pre-Sort: Index (5) Quick Partition (5) Quora (5) Randomized Algorithms (5) Resources (5) Robot (5) SPFA(Shortest Path Faster Algorithm) (5) Shuffle (5) Sieve of Eratosthenes (5) Strongly Connected Components (5) Subarray Sum (5) Sudoku (5) Suffix Tree (5) Swap (5) Threaded (5) Tree - Creation (5) Warshall Floyd (5) Word Search (5) jiuzhang (5)

Popular Posts