Click here to see the full article post
Guys, can any one help me understand why are we considering not taking the current course (in Approach 2, 3)?
@venkata-sai-krishn This needs to be done because it might be possible that the current course could be of such a long duration that it could block the future multiple smaller courses from being taken. But, by not taking this single long course, we could be benefited due a larger number of courses being taken.
Here is a minor error over here in the last solution: PriorityQueue < Integer > queue = new PriorityQueue < > ((a, b) - > b - a);
The " - >" should be "->" actually.
@Mr.Bin Thanks for pointing it out. I have corrected it.
@vinod23 Thanks Vinod.
Hi, I want to know that for Approach #3, why there may be duplicate function calls? I thought that i is increasing and we can't reach the same (i, time) twice.
consider this recursion tree (i,time). left branch is not_taken and right is taken and courses=1 and courses=1.
(0,0) / \ (1,0) (1,1) \ / (2,1) (2,1)
(2,1) is the redundant call.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.