1235. Maximum Profit in Job Scheduling | DP | Binary Search

  Рет қаралды 5,526

Aryan Mittal

Aryan Mittal

Күн бұрын

Пікірлер: 26
@MohdNasir9927
@MohdNasir9927 9 ай бұрын
Bhaiya, why do we have to sort by starttime, I understood that for optimization we have to sort according to the starttime for calculating the lower bound, but without sorting and using the take notTake technique the solution is giving the wrong answer. Why? Can you explain why? class Solution { public: int Recursion(int index, vector& startTime, vector& endTime, vector& profit, int prev, vector& dp){ if(index >= startTime.size()) return 0; if(dp[index][prev] != -1) return dp[index][prev]; int take = 0; if(startTime[index] >= prev) take = profit[index] + Recursion(index+1, startTime, endTime, profit, endTime[index], dp); int notTake = Recursion(index+1, startTime, endTime, profit, prev, dp); return dp[index][prev] = max(take, notTake); } int jobScheduling(vector& startTime, vector& endTime, vector& profit) { int n = startTime.size(); int maxi = *max_element(endTime.begin(), endTime.end()); vector dp(n, vector(maxi+1, -1)); return Recursion(0, startTime, endTime, profit, 0, dp); } };
@ishabharwal1699
@ishabharwal1699 9 ай бұрын
i have the same question. Please do tell if you have found the answer.
@dayashankarlakhotia4943
@dayashankarlakhotia4943 9 ай бұрын
public int jobScheduling (int[]startTime,int[]endTime,int[]profit){ int[][]jobs=new int[startTime.length][3]; fof(int i=0;ia[1]-b[1]); TreeMapmpp=new TreeMap(); mpp.put(0,0); int max=0; for(int[]job:jobs){ int cur=mpp.floorEntry(job[0]).getValue()+job[2]); max=Math.max(max,cur); mpp.put(job[1],max); } return max; } tc=nlogn; sc=0(n);
@pwjikashishya8883
@pwjikashishya8883 9 ай бұрын
same doubt.Please do let me know if you will find the answer
@ARYANMITTAL
@ARYANMITTAL 9 ай бұрын
See, always to prove something is wrong, take a counter example, for ex: 2 jobs [ 9, 20, 3] & [5, 7, 2] - so, job1 is at index0 with start time as 9, while job2 at index1 with start time as 5. Now, if you take job0 then profit is 3, but then you need to search i+1 for a start time of greater than equal to 9, which it won’t be able to find, as next start time i.e. of i+1 is 5. (Forget the skip case, as take case answers the question) Thus, if you don’t want to sort, then don’t do i+1, start back from index 0, but also maintain parallelly that what all index have been visited - so that you don’t re use the already used index. Which will add extra n in both space & time. Thus, best thing is sort, it solves 2 problems, i hope that helps :)
@MohdNasir9927
@MohdNasir9927 9 ай бұрын
​@@ARYANMITTALThank you so much bhaiya for the great explanation.
@hemaleka3674
@hemaleka3674 9 ай бұрын
All thanks to you now I love programming. Your explanation makes a complex problem easy
@muskandebnath6638
@muskandebnath6638 8 ай бұрын
Awesome explanation bhaiya... idk for how long i was just skipping this question as i was not able to understand other explanations at the first time. But now I have picked the right video and it cleared all my doubts.
@akshajjoshy8971
@akshajjoshy8971 9 ай бұрын
bro u r underrated , I come here for all daily question explanations. Good work bro❣
@sachinvarma9949
@sachinvarma9949 3 ай бұрын
awesome explanation
@kaushiksen2190
@kaushiksen2190 9 ай бұрын
Ok so the space complexity is O(N)+O(N) right for stack space and dp array space? Thanks for this wonderful explanation bhaiya
@reddotcheese
@reddotcheese 9 ай бұрын
Great explanation. Good work
@nishantdehariya5769
@nishantdehariya5769 7 ай бұрын
Very nice
@niteshchoudhary7705
@niteshchoudhary7705 9 ай бұрын
ThankYou so much for your explanation :-)
@mohdkhaleeq7468
@mohdkhaleeq7468 9 ай бұрын
how space complexity is O(n) while we are creating 2D array O(n) is for recursion stack space
@lilgainz
@lilgainz 9 ай бұрын
Bro wo arr 2N lega space bs
@aditimahabole1761
@aditimahabole1761 9 ай бұрын
nice explanation!
@lilgainz
@lilgainz 9 ай бұрын
Again killed it bro
@TON-108
@TON-108 9 ай бұрын
Bhaiya Please upload Day 3 #100DaysPlacement
@ARYANMITTAL
@ARYANMITTAL 9 ай бұрын
Bro, vo Day2 & Day3, kal ki video me he tha, aaj Day4 aaega, this is because insta pr parallely explanation jaata hai, so we have to go Day by Day, everyday ❤️🫡
@TON-108
@TON-108 9 ай бұрын
@@ARYANMITTAL OkOk i got confused 😅
@FinanceMode14
@FinanceMode14 9 ай бұрын
Why Start time and not end time?
@user-vaidesh
@user-vaidesh 9 ай бұрын
U can also it by using end time and also by using upper bound function
@sarthakgoel1267
@sarthakgoel1267 9 ай бұрын
bhai tum konsi class m ho?
@harikrushnasuhagiya3925
@harikrushnasuhagiya3925 9 ай бұрын
killed it bro
@itsNaveen9
@itsNaveen9 7 ай бұрын
too much over action ! actually disturbing
Maximum Profit in Job Scheduling - Leetcode 1235 - Python
14:45
NeetCodeIO
Рет қаралды 33 М.
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 27 МЛН
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 59 МЛН
Как не носить с собой вещи
00:31
Miracle
Рет қаралды 1,2 МЛН
VAMPIRE DESTROYED GIRL???? 😱
00:56
INO
Рет қаралды 8 МЛН
Binary Search Algorithm - Computerphile
18:34
Computerphile
Рет қаралды 162 М.
L6. Job Sequencing Problem | Greedy Algorithm Playlist
16:07
take U forward
Рет қаралды 43 М.
310. Minimum Height Trees | BFS | Topological Sort | Graphs
24:47
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 488 М.
1335. Minimum Difficulty of a Job Schedule | DP - 3 Ways
32:24
Aryan Mittal
Рет қаралды 3 М.
Job Sequencing Problem | Greedy Algorithms
17:00
take U forward
Рет қаралды 160 М.
Object Oriented Programming is not what you think it is. This is why.
13:36
Fake watermelon by Secret Vlog
00:16
Secret Vlog
Рет қаралды 27 МЛН