ProgrammingHardAmazon OA · Flipkart coding round

Which of the following problems can be solved correctly by a greedy algorithm that sorts by end time, when given the intervals and asked for the maximum number of non-overlapping intervals?

  1. A. Activity selection: sort by finish time and keep each interval that starts after the last one kept
  2. B. Minimum number of coins for an arbitrary coin set, sorting coins by value
  3. C. 0/1 knapsack, sorting items by value per weight
  4. D. Longest path in a general weighted graph, sorting edges by weight

Correct answer: A. Activity selection: sort by finish time and keep each interval that starts after the last one kept

Interval scheduling is solved by earliest finish time: choosing the interval that ends first leaves the most room. The other problems need DP or are not solved by this greedy rule.

More Python Programming questions

Exams that ask this topic