Leader in an Array (Code / Algorithm)

A leader in an array is an element for which all elements on its right side are less than its value. There can be multiple leaders in an array.

Пікірлер: 39

  • @Amitakd2023
    @Amitakd2023 Жыл бұрын

    thank you sir.your explanation is best explanations in whole youtube.

  • @prachiyadav1611
    @prachiyadav16116 жыл бұрын

    Is there any video on general tree ? (Trees)

  • @khaledhariz6320
    @khaledhariz63203 жыл бұрын

    Sir, i think in the 2nd method that the condition is arr[i]>=mfr and the iteration start from n-1?

  • @KomalSinghbooks
    @KomalSinghbooks5 жыл бұрын

    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!

  • @BECSAQUIB
    @BECSAQUIB3 жыл бұрын

    Great work! Keep it up

  • @user-pd2oi7eq3l
    @user-pd2oi7eq3l5 ай бұрын

    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

  • @ArjunSingh-ef9oe
    @ArjunSingh-ef9oe9 ай бұрын

    very nice explaination sir

  • @atishnarlawar1177
    @atishnarlawar11776 жыл бұрын

    Are you not just finding the max element in the array ?

  • @bhavadiph.gothadiya4026
    @bhavadiph.gothadiya40264 жыл бұрын

    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,,

  • @FrozenByTheSun
    @FrozenByTheSun6 жыл бұрын

    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

  • @gurmeetchawla8362
    @gurmeetchawla83626 жыл бұрын

    hi vivekanand, if 16 is the rightmost element then what are your thoughts about this algo.

  • @santhuravikanti4988

    @santhuravikanti4988

    5 жыл бұрын

    i think if condition is not satisfied then mfr is the 16,please correct me if my understanding is wrong

  • @pradipkumardas1738
    @pradipkumardas17384 жыл бұрын

    always try to run the code after explanation

  • @bqrkhn
    @bqrkhn5 жыл бұрын

    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.

  • @Ankit13555
    @Ankit135556 жыл бұрын

    why dont we return the max element in array and last element in array.....please tell me where test cases will fail

  • @vivekanandkhyade

    @vivekanandkhyade

    6 жыл бұрын

    { 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.

  • @vivekanandkhyade

    @vivekanandkhyade

    6 жыл бұрын

    Yes and 40 is also the leader.

  • @Ankit13555

    @Ankit13555

    6 жыл бұрын

    Vivekanand Khyade - Algorithm Every Day means only move from right to left is only way..... thankyou for clearing the doubt

  • @jaysahu357
    @jaysahu3576 жыл бұрын

    nice sir

  • @digitaltanzeel1056
    @digitaltanzeel10562 жыл бұрын

    Can anyone code in python

  • @suhailmir832
    @suhailmir8326 жыл бұрын

    if(j==n){ printf("Print the leader");// this needs to be outside the inner for loop }

  • @shivprachigupta7124

    @shivprachigupta7124

    2 жыл бұрын

    Show 0 leader... while run

  • @shivprachigupta7124
    @shivprachigupta71242 жыл бұрын

    Can you provide full code for this😣

  • @shivprachigupta7124

    @shivprachigupta7124

    2 жыл бұрын

    Showing 0 leader...

  • @shivprachigupta7124

    @shivprachigupta7124

    2 жыл бұрын

    After i input values

  • @divyalakshmip925
    @divyalakshmip9255 жыл бұрын

    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

  • @anandjha5353

    @anandjha5353

    4 жыл бұрын

    Its correct output should be 3, 5, 7 only

  • @letsexplorewith_jaggu98

    @letsexplorewith_jaggu98

    3 жыл бұрын

    @@anandjha5353 7 7 5 3 should be the answer sir

  • @anandjha5353

    @anandjha5353

    3 жыл бұрын

    @@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.

  • @letsexplorewith_jaggu98

    @letsexplorewith_jaggu98

    3 жыл бұрын

    @@anandjha5353 it's okay sir.. I just said included with duplicates too.. I just remembered you that Divyalakshmi missed 5 in her answer.

  • @anandjha5353

    @anandjha5353

    3 жыл бұрын

    @@letsexplorewith_jaggu98 right bro 👍

  • @9738803535
    @97388035355 жыл бұрын

    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

  • @ganeshnanekar3764

    @ganeshnanekar3764

    4 жыл бұрын

    Just inverse an op... you'll get the write answer

  • @user-pd2oi7eq3l

    @user-pd2oi7eq3l

    5 ай бұрын

    for that u should take " for(i=size-1;i>=0;i--) " while doing logic

  • @NCCSAyesha-st3hv
    @NCCSAyesha-st3hv4 жыл бұрын

    Fucking internet

  • @NCCSAyesha-st3hv
    @NCCSAyesha-st3hv4 жыл бұрын

    Patang Tu se