Weighted Job Scheduling


Weighted Job Scheduling - GeeksforGeeks
Given N jobs where every job is represented by following three elements of it.
  1. Start Time
  2. Finish Time
  3. Profit or Value Associated
Find the maximum profit subset of jobs such that no two jobs in the subset overlap.
Example:


Input: Number of Jobs n = 4
       Job Details {Start Time, Finish Time, Profit}
       Job 1:  {1, 2, 50} 
       Job 2:  {3, 5, 20}
       Job 3:  {6, 19, 100}
       Job 4:  {2, 100, 200}
Output: The maximum profit is 250.
We can get the maximum profit by scheduling jobs 1 and 4.
Note that there is longer schedules possible Jobs 1, 2 and 3 
but the profit with this schedule is 20+50+100 which is less than 250. 
A simple version of this problem is discussed here where every job has same profit or value. The Greedy Strategy for activity selection doesn’t work here as the longer schedule may have smaller profit or value.
https://www.geeksforgeeks.org/weighted-job-scheduling-log-n-time/
1) First sort jobs according to finish time.
2) Now apply following recursive process. 
   // Here arr[] is array of n jobs
   findMaximumProfit(arr[], n)
   {
     a) if (n == 1) return arr[0];
     b) Return the maximum of following two profits.
         (i) Maximum profit by excluding current job, i.e., 
             findMaximumProfit(arr, n-1)
         (ii) Maximum profit by including the current job            
   }

How to find the profit including current job?
The idea is to find the latest job before the current job (in 
sorted array) that doesn't conflict with current job 'arr[n-1]'. 
Once we find such a job, we recur for all jobs till that job and
add profit of current job to result.
In the above example, "job 1" is the latest non-conflicting
for "job 4" and "job 2" is the latest non-conflicting for "job 3".

class Job
{
    int start, finish, profit;
    // Constructor
    Job(int start, int finish, int profit)
    {
        this.start = start;
        this.finish = finish;
        this.profit = profit;
    }
}
// Used to sort job according to finish times
class JobComparator implements Comparator<Job>
{
    public int compare(Job a, Job b)
    {
        return a.finish < b.finish ? -1 : a.finish == b.finish ? 0 : 1;
    }
}
    /* A Binary Search based function to find the latest job
      (before current job) that doesn't conflict with current
      job.  "index" is index of the current job.  This function
      returns -1 if all jobs before index conflict with it.
      The array jobs[] is sorted in increasing order of finish
      time. */
    static public int binarySearch(Job jobs[], int index)
    {
        // Initialize 'lo' and 'hi' for Binary Search
        int lo = 0, hi = index - 1;
        // Perform binary Search iteratively
        while (lo <= hi)
        {
            int mid = (lo + hi) / 2;
            if (jobs[mid].finish <= jobs[index].start)
            {
                if (jobs[mid + 1].finish <= jobs[index].start)
                    lo = mid + 1;
                else
                    return mid;
            }
            else
                hi = mid - 1;
        }
        return -1;
    }
    // The main function that returns the maximum possible
    // profit from given array of jobs
    static public int schedule(Job jobs[])
    {
        // Sort jobs according to finish time
        Arrays.sort(jobs, new JobComparator());
        // Create an array to store solutions of subproblems.
        // table[i] stores the profit for jobs till jobs[i]
        // (including jobs[i])
        int n = jobs.length;
        int table[] = new int[n];
        table[0] = jobs[0].profit;
        // Fill entries in M[] using recursive property
        for (int i=1; i<n; i++)
        {
            // Find profit including the current job
            int inclProf = jobs[i].profit;
            int l = binarySearch(jobs, i);
            if (l != -1)
                inclProf += table[l];
            // Store maximum of including and excluding
            table[i] = Math.max(inclProf, table[i-1]);
        }
        return table[n-1];
    }

Find the maximum profit subset of jobs such that no two jobs in the subset overlap.
1) First sort jobs according to finish time.
2) Now apply following recursive process. 
   // Here arr[] is array of n jobs
   findMaximumProfit(arr[], n)
   {
     a) if (n == 1) return arr[0];
     b) Return the maximum of following two profits.
         (i) Maximum profit by excluding current job, i.e., 
             findMaximumProfit(arr, n-1)
         (ii) Maximum profit by including the current job            
   }

How to find the profit excluding current job?
The idea is to find the latest job before the current job (in 
sorted array) that doesn't conflict with current job 'arr[n-1]'. 
Once we find such a job, we recur for all jobs till that job and
add profit of current job to result.
In the above example, for job 1 is the latest non-conflicting
job for job 4 and job 2 is the latest non-conflicting job for
job 3.
DP: O(n^2)
// The main function that returns the maximum possible
// profit from given array of jobs
int findMaxProfit(Job arr[], int n)
{
    // Sort jobs according to finish time
    sort(arr, arr+n, myfunction);
    // Create an array to store solutions of subproblems.  table[i]
    // stores the profit for jobs till arr[i] (including arr[i])
    int *table = new int[n];
    table[0] = arr[0].profit;
    // Fill entries in M[] using recursive property
    for (int i=1; i<n; i++)
    {
        // Find profit including the current job
        int inclProf = arr[i].profit;
        int l = latestNonConflict(arr, i);
        if (l != -1)
            inclProf += table[l];
        // Store maximum of including and excluding
        table[i] = max(inclProf, table[i-1]);
    }
    // Store result and free dynamic memory allocated for table[]
    int result = table[n-1];
    delete[] table;
    return result;
}

// Find the latest job (in sorted array) that doesn't
// conflict with the job[i]. If there is no compatible job,
// then it returns -1.
int latestNonConflict(Job arr[], int i)
{
    for (int j=i-1; j>=0; j--)
    {
        if (arr[j].finish <= arr[i-1].start)
            return j;
    }
    return -1;
}

O(NlogN): Use Binary Search to find non-conflict
http://buttercola.blogspot.com/2014/10/facebook-weighted-interval-scheduling.html
  • Sort the intervals by end time. 
  • Define the DP array
    • dp[n + 1], where dp[i] means the the first set non-overlapping of i jobs, save the maximum cost. 
  • Initial state: dp[0] = 0;
  • Transit function:
    • dp[i] = Math.max(dp[i - 1], dp[p[i - 1] + 1] + interval[i - 1].cost ), where the p[i - 1] is the index with the end time that is closest to interval[i - 1].end
  • Final state: dp[n].
    public int weightedIntervalScheduling(List<Event> events) {
        if (events == null || events.size() == 0) {
            return 0;
        }
         
        // sort by end time.
        Collections.sort(events, new EventComparator());
         
        int[] dp = new int[events.size() + 1];
        dp[0] = 0;
         
        for (int i = 1; i <= events.size(); i++) {
            int noChoose = dp[i - 1]; // no choose
            int idx = findNearestIndex(i, events, events.get(i - 1).start);
            int choose = dp[idx + 1] + events.get(i - 1).cost;
            dp[i] = Math.max(choose, noChoose);
        }
         
        return dp[events.size()];
    }
    // binary search for the end index which is nearest to target
    private int findNearestIndex(int end, List<Event> events, int target) {
        int lo = 0;
        int hi = end - 1;
         
        if (target < events.get(0).end) {
            return -1;
        }
         
        if (target > events.get(hi).end) {
            return hi;
        }
         
        while (lo + 1 < hi) {
            int mid = lo + (hi - lo) / 2;
            if (events.get(mid).end == target) {
                return mid;
            else if (events.get(mid).end > target) {
                hi = mid;
            } else {
                lo = mid;
            }
        }
         
        if (events.get(lo).end == target) {
            return lo;
        } else if (events.get(hi).end == target) {
            return hi;
        } else {
            return lo;
        }
    }
    private class EventComparator implements Comparator<Event> {
        public int compare(Event a, Event b) {
            return a.end - b.end;
        }
    }



http://www.geeksforgeeks.org/find-jobs-involved-in-weighted-job-scheduling/
we will also print the jobs invloved in maximum profit.
int findMaxProfit(Job arr[], int n)
{
    // Sort jobs according to finish time
    sort(arr, arr + n, jobComparator);
    // Create an array to store solutions of subproblems.
    // DP[i] stores the Jobs involved and their total profit
    // till arr[i] (including arr[i])
    weightedJob DP[n];
    // initialize DP[0] to arr[0]
    DP[0].value = arr[0].profit;
    DP[0].job.push_back(arr[0]);
    // Fill entries in DP[] using recursive property
    for (int i = 1; i < n; i++)
    {
        // Find profit including the current job
        int inclProf = arr[i].profit;
        int l = latestNonConflict(arr, i);
        if (l != - 1)
            inclProf += DP[l].value;
        // Store maximum of including and excluding
        if (inclProf > DP[i - 1].value)
        {
            DP[i].value = inclProf;
            // including previous jobs and current job
            DP[i].job = DP[l].job;
            DP[i].job.push_back(arr[i]);
        }
        else
            // excluding the current job
            DP[i] = DP[i - 1];
    }
    // DP[n - 1] stores the result
    cout << "Optimal Jobs for maximum profits are\n" ;
    for (int i=0; i<DP[n-1].job.size(); i++)
    {
        Job j = DP[n-1].job[i];
        cout << "(" << j.start << ", " << j.finish
             << ", " << j.profit << ")" << endl;
    }
    cout << "\nTotal Optimal profit is " << DP[n - 1].value;
}
http://www.fgdsb.com/2015/01/03/non-overlapping-jobs/
What if we want the solution itself? A. Do some post-processing – “traceback”
// A recursive function that returns the maximum possible
// profit from given array of jobs.  The array of jobs must
// be sorted according to finish time.
int findMaxProfitRec(Job arr[], int n)
{
    // Base case
    if (n == 1) return arr[n-1].profit;
    // Find profit when current job is inclueded
    int inclProf = arr[n-1].profit;
    int i = latestNonConflict(arr, n);
    if (i != -1)
      inclProf += findMaxProfitRec(arr, i+1);
    // Find profit when current job is excluded
    int exclProf = findMaxProfitRec(arr, n-1);
    return max(inclProf,  exclProf);
}
int findMaxProfit(Job arr[], int n)
{
    // Sort jobs according to finish time
    sort(arr, arr+n, myfunction);
    return findMaxProfitRec(arr, n);
}
The above solution may contain many overlapping subproblems. For example if lastNonConflicting() always returns previous job, then findMaxProfitRec(arr, n-1) is called twice and the time complexity becomes O(n*2n). As another example when lastNonConflicting() returns previous to previous job, there are two recursive calls, for n-2 and n-1. In this example case, recursion becomes same as Fibonacci Numbers.
http://blueocean-penn.blogspot.com/2015/01/weighted-job-scheduling.html
 public class Job implements Comparable<Job>{
int startendprofit;
public int compareTo(Job other){
return this.end - other.end;
}
}
public int maxProfit(Job[] jobs){
//table[i] store the max profit including ith job
int[] table = new int[jobs.length];
Arrays.sort(jobs);
table[0] = jobs[0].profit;
for(int k = 1; k<jobs.length; k++){
int max = Integer.MIN_VALUE;
int m = binarySearch(jobs, 0, k-1, jobs[k].start);
while(m>=0)
max = Math.max(max, table[m--]);
table[k] = max + jobs[k].profit;
}
int max = Integer.MIN_VALUE;
for(int k=0; k<jobs.length; k++){
max = Math.max(table[k], max);
}
return max;
}
public int binarySearch(Job[] jobs, int start, int end, int k){
if(jobs[start].end > k)
return start-1;
while(start<end-1){
int mid = (start+end)>>>1;
if(jobs[mid].end > k)
end = mid;
else
start = mid;
}
return jobs[end].end<=k?end:start;
}
http://www.zrzahid.com/weighted-jobinterval-scheduling-activity-selection-problem/
Optimal Substructure
Let MAX_PROFIT(j) = value of optimal solution to the problem consisting of job requests {1, 2, . . . , j }.
  • Case 1: MAX_PROFIT selects job j.
    • can’t use incompatible jobs { qj + 1, qj + 2, . . . , j-1 }
    • must include optimal solution to problem consisting of remaining compatible jobs { 1, 2, . . . , qj }
  • Case 2: MAX_PROFIT does not select job j.
    • must include optimal solution to problem consisting of remaining compatible jobs { 1, 2, . . . , j - 1 }
MAX_PROFIT(j) = 0 if j=0;
              = max{wj+MAX_PROFIT(qj), MAX_PROFIT(j-1)}; // max of including and excluding
Weighted-Activity-Selection(S):  // S = list of activities
  
       sort S by finish time
       MAX_PROFIT[0] = 0
      
       for j = 1 to n:
           qj = BST.floor(S[j].start)//binary search to find activity with finish time <= start time for j
           MAX_PROFIT[j] = MAX(MAX_PROFIT[j-1], MAX_PROFIT[qj] + w(j))
           
       return MAX_PROFIT[n]
//largest element smaller than or equal to key
public static int binarySearchLatestCompatibleJob(Job[] A, int l, int h, int key){
 int mid = (l+h)/2;
 
 if(A[h].finish <= key){
  return h;
 }
 if(A[l].finish > key ){
  return -1;
 }
 
 if(A[mid].finish == key){
  return mid;
 }
 //mid is greater than key, so floor is either mid-1 or it exists in A[l..mid-1]
 else if(A[mid].finish > key){
  if(mid-1 >= l && A[mid-1].finish <= key){
   return mid-1;
  }
  else{
   return binarySearchLatestCompatibleJob(A, l, mid-1, key);
  }
 }
 //mid is less than key, so floor is either mid or it exists in A[mid+1....h]
 else{
  if(mid+1 <= h && A[mid+1].finish > key){
   return mid;
  }
  else{
   return binarySearchLatestCompatibleJob(A, mid+1, h, key);
  }
 }
}

public static int weightedActivitySelection(Job[] jobs){
 int n = jobs.length;
 int profit[] = new int[n+1];
 int q[] = new int[n];
 
 //sort according to finish time
 Arrays.sort(jobs);
 
 //find q's - O(nlgn)
 for(int i = 0; i< n; i++){
  q[i] = binarySearchLatestCompatibleJob(jobs, 0, n-1, jobs[i].start);
 }
 
 //compute optimal profits - O(n)
 profit[0] = 0;
 for(int j = 1; j<=n; j++){
  int profitExcluding = profit[j-1];
  int profitIncluding = jobs[j-1].weight;
  if(q[j-1] != -1){
   profitIncluding += profit[q[j-1]+1];
  }
  profit[j] = Math.max(profitIncluding, profitExcluding);
 }
 return profit[n];
}
http://buttercola.blogspot.com/2014/10/facebook-weighted-interval-scheduling.html
        outputSolution(dp, events, events.size(), result);   
    private void outputSolution(int[] dp, List<Event> events, int i, List<Integer> result) {
        if (i == 0) {
            return;   
        }
         
        int idx = findNearestIndex(i, events, events.get(i - 1).start);
        if (dp[idx + 1] + events.get(i - 1).cost > dp[i - 1]) {
            result.add(i - 1);
            outputSolution(dp, events, idx + 1, result);
        } else {
            outputSolution(dp, events, i - 1, result);
        }
    }

http://www.cnblogs.com/reynold-lei/p/4390148.html
25     public static ArrayList<Job> findJobsWithMaxCost(Job[] jobList){
26         ArrayList<Job> result = new ArrayList<Job> ();
27         if(jobList == null || jobList.length == 0) return result;
28         Arrays.sort(jobList, new Comparator<Job>(){
29             public int compare(Job j1, Job j2){
30                 return j1.end_time > j2.end_time ? 1 : (j1.end_time == j2.end_time ? 0 : -1);
31             }
32         });
33         int len = jobList.length;
34         int[][] dp = new int[len + 1][jobList[len - 1].end_time + 1];
35         for(int i = 1; i <= len; i ++){
36             Job tmp = jobList[i - 1];
37             int start = tmp.start_time;
38             int end = tmp.end_time;
39             for(int j = 0; j < dp[0].length; j ++){
40                 if(j < end){
41                     dp[i][j] = dp[i - 1][j];
42                 }else if(j == end){
43                     dp[i][j] = Math.max(dp[i - 1][start] + tmp.cost, dp[i - 1][j]);
44                 }else{
45                     dp[i][j] = dp[i][j - 1];
46                 }
47             }
48         }
49 
50         int i = dp[0].length - 1;
51         while(i > 0){
52             if(dp[len][i] == dp[len][i - 1]) i --;
53             else{
54                 int j = len;
55                 while(j > 0 && dp[j][i] == dp[j - 1][i]) j --;
56                 result.add(jobList[j - 1]);
57                 i --;
58             }
59         }
60         return result;
61     }

http://siyang2notleetcode.blogspot.com/2015/02/job-schedule.html
Greedy Algorithms | Set 1 (Activity Selection Problem)
Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. Greedy algorithms are used for optimization problems. An optimization problem can be solved using Greedy if the problem has the following property: At every step, we can make a choice that looks best at the moment, and we get the optimal solution of the complete problem.
If a Greedy Algorithm can solve a problem, then it generally becomes the best method to solve that problem as the Greedy algorithms are in general more efficient than other techniques like Dynamic Programming. But Greedy algorithms cannot always be applied. For example, Fractional Knapsack problem (See this) can be solved using Greedy, but 0-1 Knapsack cannot be solved using Greedy.

You are given n activities with their start and finish times. Select the maximum number of activities that can be performed by a single person, assuming that a person can only work on a single activity at a time.
Example:
Consider the following 6 activities. 
     start[]  =  {1, 3, 0, 5, 8, 5};
     finish[] =  {2, 4, 6, 7, 9, 9};
The maximum set of activities that can be executed 
by a single person is {0, 1, 3, 4}


The greedy choice is to always pick the next activity whose finish time is least among the remaining activities and the start time is more than or equal to the finish time of previously selected activity. We can sort the activities according to their finishing time so that we always consider the next activity as minimum finishing time activity.

1) Sort the activities according to their finishing time
2) Select the first activity from the sorted array and print it.
3) Do following for remaining activities in the sorted array.
…….a) If the start time of this activity is greater than or equal to the finish time of previously selected activity then select this activity and print it.
void printMaxActivities(Activitiy arr[], int n)
{
    // Sort jobs according to finish time
    sort(arr, arr+n, activityCompare);
    cout << "Following activities are selected n";
    // The first activity always gets selected
    int i = 0;
    cout << "(" << arr[i].start << ", " << arr[i].finish << "), ";
    // Consider rest of the activities
    for (int j = 1; j < n; j++)
    {
      // If this activity has start time greater than or
      // equal to the finish time of previously selected
      // activity, then select it
      if (arr[j].start >= arr[i].finish)
      {
          cout << "(" << arr[j].start << ", "
              << arr[j].finish << "), ";
          i = j;
      }
    }
}
How does Greedy Choice work for Activities sorted according to finish time?
Let the give set of activities be S = {1, 2, 3, ..n} and activities be sorted by finish time. The greedy choice is to always pick activity 1. How come the activity 1 always provides one of the optimal solutions. We can prove it by showing that if there is another solution B with first activity other than 1, then there is also a solution A of same size with activity 1 as first activity. Let the first activity selected by B be k, then there always exist A = {B – {k}} U {1}.(Note that the activities in B are independent and k has smallest finishing time among all. Since k is not 1, finish(k) >= finish(1)).
http://www.zrzahid.com/weighted-jobinterval-scheduling-activity-selection-problem/
Consider the following 6 activities.
start[] = {1, 3, 0, 5, 8, 5};
finish[] = {2, 4, 6, 7, 9, 9};
The maximum set of activities that can be executed
by a single machine/job is {0, 1, 3, 4}.
Greedy Solution
  • Sort the activities according to their finishing time
  • Select the first activity from the sorted array and print it.
  • For each of the remaining activities in the sorted array – If the start time of this activity is greater than the finish time of previously selected activity then select this activity and send it to output channel.
The simple activity selection problem described above is a weighted specialization with weight = 1. 
      public static int longestChain(Job[] pairs){
  Arrays.sort(pairs); //Assume that Pair class implements comparable with the compareTo() method such that (a, b) < (c,d) iff b<c
  int chainLength = 0;
  
  //select the first pair of the sorted pairs array
  pairs[0].print(); //assume print method prints the pair as “(a, b) ”
  chainLength++;
  int prev = 0;

  for(int i=1;i<pairs.length; i++)
  {
   if(pairs[i].start >= pairs[prev].finish)
   {
    chainLength++;
    prev = i;
   }
  }
  return chainLength; 
 }
Read full article from Weighted Job Scheduling - 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