good explanation sir, you would take (i=size-1) in for loop to get correct in different test cases ,if you take size-2 first array will miss for some testcases
The O(n) solution will pint the answer in reverse order which can lead to the Wrong answer, so a better way would be to store the answer in another array and print in reverse order :) BTW nice explanation!
{ 1 , 25 , 50 , 40 , 30 , 20 , 21 , 28 } here 50 is max and 28 is last element. Both are Leaders. But 30 is also the leader beacause all elements on right side of 30 are less than 30.
The actual question is: Given an array, print all the leaders. Now if we scan from the right and keep current max element, we can easily print the elements. Check out geeksforgeeks.
but here one problem in this solution if print all leader number in order , then we have to maintain the order of leader because this solution return leader number in reverse order,,
@@letsexplorewith_jaggu98 An element is leader if it is greater than all the elements to its right side. So the output should be 7 5 3 only. If we are counting 7 two times then second seven is equal not greater to all its right element so this should not be included.
thank you sir.your explanation is best explanations in whole youtube.
good explanation sir, you would take (i=size-1) in for loop to get correct in different test cases ,if you take size-2 first array will miss for some testcases
The O(n) solution will pint the answer in reverse order which can lead to the Wrong answer, so a better way would be to store the answer in another array and print in reverse order :) BTW nice explanation!
very nice explaination sir
Great work! Keep it up
Is there any video on general tree ? (Trees)
Sir, i think in the 2nd method that the condition is arr[i]>=mfr and the iteration start from n-1?
hi vivekanand, if 16 is the rightmost element then what are your thoughts about this algo.
i think if condition is not satisfied then mfr is the 16,please correct me if my understanding is wrong
Thanks for the video. Your explanations are the best.
Can you make one about external sorting? I can’t get it. I’ve sent you an email with the problem
why dont we return the max element in array and last element in array.....please tell me where test cases will fail
{ 1 , 25 , 50 , 40 , 30 , 20 , 21 , 28 }
here 50 is max and 28 is last element. Both are Leaders. But 30 is also the leader beacause all elements on right side of 30 are less than 30.
Yes and 40 is also the leader.
Vivekanand Khyade - Algorithm Every Day means only move from right to left is only way..... thankyou for clearing the doubt
The actual question is: Given an array, print all the leaders.
Now if we scan from the right and keep current max element, we can easily print the elements. Check out geeksforgeeks.
Are you not just finding the max element in the array ?
nice sir
but here one problem in this solution
if print all leader number in order , then we have to maintain the order of leader because this solution return leader number in reverse order,,
In greeks for greeks for given below input they are looking for sequential output
Example:
Input array : 16 17 4 3 5 2
Output : 17 5 2
Just inverse an op... you'll get the write answer
for that u should take " for(i=size-1;i>=0;i--) " while doing logic
Can you provide full code for this😣
Showing 0 leader...
After i input values
always try to run the code after explanation
if(j==n){
printf("Print the leader");// this needs to be outside the inner for loop
}
Show 0 leader... while run
sir
this method is not working for this input
7 4 7 5 3
it gives a o/p
7 3
but its actual o/p is
7 7 3
Its correct output should be 3, 5, 7 only
@@anandjha5353 7 7 5 3 should be the answer sir
@@letsexplorewith_jaggu98 An element is leader if it is greater than all the elements to its right side. So the output should be 7 5 3 only. If we are counting 7 two times then second seven is equal not greater to all its right element so this should not be included.
@@anandjha5353 it's okay sir.. I just said included with duplicates too..
I just remembered you that Divyalakshmi missed 5 in her answer.
@@letsexplorewith_jaggu98 right bro 👍
Can anyone code in python
Fucking internet
Patang Tu se