Can anyone tell me what is the mistake that I am making with my code? class Solution: def scheduleCourse(self, courses: List[List[int]]) -> int: courses.sort(key = lambda x:x[1])
maxindex = None output = [] currtime = 0
for i in range(len(courses)): if currtime + courses[i][0] courses[maxindex][0]: maxindex = i else: maxindex = i else: if maxindex is not None: if courses[i][0] < courses[maxindex][0]: #now we are interested in swapping with maxindex if (currtime + courses[i][0]) - courses[maxindex][0] < courses[i][1]: #it should also satisfy the above condition currtime -= courses[maxindex][0] output.remove(courses[maxindex]) output.append(courses[i]) currtime += courses[i][0] maxindex = i
Can anyone tell me what is the mistake that I am making with my code? class Solution: def scheduleCourse(self, courses: List[List[int]]) -> int: courses.sort(key = lambda x:x[1])
maxindex = None output = [] currtime = 0
for i in range(len(courses)): if currtime + courses[i][0] courses[maxindex][0]: maxindex = i else: maxindex = i else: if maxindex is not None: if courses[i][0] < courses[maxindex][0]: #now we are interested in swapping with maxindex if (currtime + courses[i][0]) - courses[maxindex][0] < courses[i][1]: #it should also satisfy the above condition currtime -= courses[maxindex][0] output.remove(courses[maxindex]) output.append(courses[i]) currtime += courses[i][0] maxindex = i
If you have used a variable to store the index of maximum value and using a list/array instead of a maxheap, then retrieving the value with the index will take time.
Brilliant Khushbu....... I really like your visualizations in every problem which makes it easy to understand. You made the hard problem very easy.
Thanks
Thank you teacher! I really appreaciate that smooth explanation of what is going on with this leetcode problem :)
Glad you liked it !!
great video, thanks for the explanation
Thaks mam
Thanks
smoothest explaination thanks
too amazing explanation
Very well explained!
Thank you for making such amazing videos.
Great Work!!!
thank you, relly clear explanation
Thank you!
Well explained !!
thanks
Thanks mam !!
helped a lot :) .
Amazing explanation!! Thank you so much
best explanation ,thank you so much ma'am !!
Very well explained. Thanks.
You are welcome!
Thank you.. very helpful
Glad it was helpful!
A+++++ grade content mam!!!!
Thanks 😀
can't we do it in less time than nlogn? like O(n) or O(n+m). If we can avoid sorting, can we achieve better solution?
Great Explaination!👌🔥
Great solution and explanation
Thanks
Amazing work
Thanks !!
Thanks for your approch & solution. I completely understood .
Thanks
Thank you very much
Thanks
Great Explanation !!
Thanks
Awesome visualizations :)
Great Explanation
Thanks
awesome...
Thanks!!
Amazing work! Thanks a lot
Happy to help
Could you also add explanation of dp approach for this problem ? Thank you for the explanation!
sort the array based on increasing deadline and relate this problem to 0-1 knapsack, you will get it
This is amazing. Thank you so much!
best
Thanks!!
Is Time complexity=O(N log N) and space=O(N)? Correct me if I am wrong
I think in the else block we again have to check wether we can add the course or not
Can anyone tell me what is the mistake that I am making with my code?
class Solution:
def scheduleCourse(self, courses: List[List[int]]) -> int:
courses.sort(key = lambda x:x[1])
maxindex = None
output = []
currtime = 0
for i in range(len(courses)):
if currtime + courses[i][0] courses[maxindex][0]:
maxindex = i
else:
maxindex = i
else:
if maxindex is not None:
if courses[i][0] < courses[maxindex][0]:
#now we are interested in swapping with maxindex
if (currtime + courses[i][0]) - courses[maxindex][0] < courses[i][1]:
#it should also satisfy the above condition
currtime -= courses[maxindex][0]
output.remove(courses[maxindex])
output.append(courses[i])
currtime += courses[i][0]
maxindex = i
return len(output)
I am having a hard time understanding the Arrays.sort() line.
It would be a kind gesture if someone can elaborate.
It is a builtin method which sorts the array either with natural ordering or if a custom comparator is provided then with that.
Can anyone tell me what is the mistake that I am making with my code?
class Solution:
def scheduleCourse(self, courses: List[List[int]]) -> int:
courses.sort(key = lambda x:x[1])
maxindex = None
output = []
currtime = 0
for i in range(len(courses)):
if currtime + courses[i][0] courses[maxindex][0]:
maxindex = i
else:
maxindex = i
else:
if maxindex is not None:
if courses[i][0] < courses[maxindex][0]:
#now we are interested in swapping with maxindex
if (currtime + courses[i][0]) - courses[maxindex][0] < courses[i][1]:
#it should also satisfy the above condition
currtime -= courses[maxindex][0]
output.remove(courses[maxindex])
output.append(courses[i])
currtime += courses[i][0]
maxindex = i
return len(output)
You need to check where your swap is valid. That means if the duration of the course from output is higher than the current course.
Tum hi ho,
Jo,
Exam ko RAATEE laga laga ke pass karti ho...
Could you add time stamps to your video?
I tried without using Priority Queue then it is taking lot of time but it is accepted
Can anyone explain why is it so?
If you have used a variable to store the index of maximum value and using a list/array instead of a maxheap, then retrieving the value with the index will take time.
This code is giving TLE on leetcode
Ye toh totally ratant vidya hai
hello mam can i contact u in any way?
Very well explained
Glad it was helpful!
Fantastic Explanation
Thanks !!
Very good explanation thank you!
Glad it was helpful!