Maximum chain length of pairs || Dynamic programming

preview_player
Показать описание
This video explains a very important and different type of question which can be solved using one of the important dynamic programming approach. The problem is to find the maximum chain length of pairs which can be formed. This has been solved using longest increasing subsequence technique. CODE LINK is present below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)

Рекомендации по теме
Комментарии
Автор

Best part about your videos are the clarity of taught with which you are explaining. I can clearly convert to code at one go without any issues.

rakshith
Автор

Hey, you know what, your videos are really good. But I am sad to see such low views on your videos, But don't worry Keep uploading and helping students like me. The day will come you will be recognised by many of us. Kepp hurtling. BTW I am an aspiring SDE, currently in 4th year with no placement offer in hand. Totally fucked up and trying to figure out my way to Big product based company but sadly I am a very average student with high aspiration and trying hard to learn DS and algo and doing coding. I hope your videos will help me catch my dream.

sahoosiddharth
Автор

while calculating time complexity are we not considering Arrays.sort() which we do in order to sort the input?

rakshith
Автор

Why are we sorting here but not in LIS problem?

aishwantghimire
Автор

The longest chain length of 3 is correct but the actual pairs output of [15, 28] -> [39, 60] -> [50, 90] is incorrect as [39, 60] overlaps w/ [50, 90].

The correct pairs that do not overlap at all since the ending time of previous pair has to be strictly less than the starting time of the next pair would be [5, 24] -> [27, 40] -> [50, 90]

You would need to adjust the algo for reverse engineering the actual pairs that are valid non-overlapping intervals by taking the latter & not first when traversing backwards.

raysdev
Автор

Guys we can do this in O(n) time...by greedy method. Pls refer activity selection problem in geeks for geeks.

HarishAmarnath
Автор

how does [{50, 90}, {39, 60}, {15, 28}] pass the condition {a, b} {c, d} where c > b

ArunGangula
Автор

Why sorting with first value or the second value givess the same answer?

manthankhorwal
Автор

Still couldn't get why we need the LIS condition. If you can share the intuition behind the second condition, that would make things clearer.

ashishmh
Автор

Nice explanation sir....please make videos on backtracking and greedy.

sumitjindal
Автор

Solution wih nlogn
Or give some hint???

utubecom
Автор

Bro plz make next video on combination of array elements with r elements {1, 2, 3} and r= 2 then output: 1 2
1 3
2 3

shamshuddinshaik
Автор

It is not working fo rthis case {(6, 8), (3, 4)} oputput is coming 1 which should be 2

niteshagarwal
Автор

Starting value se sort karne par ans galt aa raha kyu?

harshraj
Автор

Will this logic work for the input {5, 10} {11, 7} {6, 8} {9, 10} ? The best answer here is 4. But i think your algorithm will find it as 3

alokkumarsingh
Автор

//O(N*logN)
The structure to use is as follows
struct val{
int first;
int second;
};*/


bool comp(val v1, val v2)
{
return v1.second<v2.second;

}

class Solution{
public:
/*You are required to complete this method*/


int maxChainLen(struct val p[], int n)
{
sort(p, p+n, comp);
int maxi=1;
int s=p[0].second;
for(int i=1;i<n;i++)
{
if(p[i].first > s )
{
s=p[i].second;
maxi++;
}
}

return maxi;
}
};

harshitsharma
Автор

please solve this question with python practicaly

abhaytiwari
Автор

I put dislike because you didn't explain what questions need good, i don't understand how the output

ahmadzeed
Автор

please introduce yourself in a separate video

awesome_latest_virals
Автор

bhai logic toh de kyu aisa karr rahhe hai, algo gfg se dekh k batana hai toh video kyu banna raha hai, sabb logic dekhne aate hai . try to give logic in ur videos. video me mehnat karr yaar, why waste time of students

nikhilprasad