Leaders in an array | GeeksforGeeks

Sdílet
Vložit
  • čas přidán 28. 07. 2024
  • Explanation for the article: www.geeksforgeeks.org/leaders-...
    Read More: www.geeksforgeeks.org/leaders...
    This video is contributed by Harshit Jain.
    #geeksforgeeks

Komentáře • 28

  • @apoorvgarg0204
    @apoorvgarg0204 Před 4 lety +3

    Thank you so much for these videos!

  • @sonusingh-hj2dw
    @sonusingh-hj2dw Před 4 lety +1

    In the linear time algo discussed,it will print the element in reverse order .

  • @kvenkatasivareddy5812
    @kvenkatasivareddy5812 Před 5 lety +3

    is there only one leader in the array or multiple leaders ?

  • @suryakantsapkal8242
    @suryakantsapkal8242 Před 4 lety +3

    Nicely explained!! Kudos to GFG team🙌

    • @Thowfi
      @Thowfi Před rokem

      Rtmgtreghgyhfserk.jwro-

    • @Thowfi
      @Thowfi Před rokem

      dsoee]yrttyra;/htupiutdufffffifd;uesrsssdiugyyfpfdihoffo\==

    • @Thowfi
      @Thowfi Před rokem

      Sh'py]\uugv,'i1[pr vn ch;yo[to]--

  • @archanaprakash1107
    @archanaprakash1107 Před 3 lety

    How to count the leaders in an array
    As per my question the answer should be 3 .
    As there are 3 leaders.

  • @ShubhamMishra-mz4zw
    @ShubhamMishra-mz4zw Před 3 lety

    Thanks a lot gfg...

  • @sangnguyenn2367
    @sangnguyenn2367 Před rokem

    Thank you so much

  • @wecan2729
    @wecan2729 Před 3 lety +3

    vector leaders(int a[], int n)
    {
    vectorans;
    ans.push_back(a[n-1]);
    int t=a[n-1];
    for(int i=n-2;i>=0;i--)
    {
    if(a[i]>=t)
    {
    ans.push_back(a[i]);
    t=a[i];
    }
    }
    reverse(ans.begin(),ans.end());
    return ans;
    }

  • @reyou7
    @reyou7 Před 7 lety +2

    very good, thank you!

  • @hermesmercuriustrismegistu4841

    thx a lot

  • @abhijeetjain2098
    @abhijeetjain2098 Před 5 lety +1

    this code is not giving output in java..

    • @musicquotes5357
      @musicquotes5357 Před 5 lety

      class LeadersInArray{
      public static void main(String[] args) {
      int[] arr = {16,17,4,3,5,2};
      int x = arr[arr.length-1];
      System.out.println("Leaders:
      "+ x);
      for(int i = arr.length-2; i>=0; i--){
      if(arr[i] > x){
      System.out.println(arr[i]);
      x = arr[i];
      }
      }
      }
      }

  • @sudipmahata8346
    @sudipmahata8346 Před 4 lety +1

    actual answer of the question is - 17 5 2
    when input is { 16 , 17 , 4 , 3 , 5 , 2}
    but , your answer is - 2 5 17 by this algorithm.
    so, how to print in right way.

    • @abhishekaman708
      @abhishekaman708 Před 4 lety +1

      Despite printing it, Store the values in a vector. Return the vector and print it in reverse order.

    • @lucky_raiser
      @lucky_raiser Před 3 lety

      @@abhishekaman708 but still it is not optimized.

  • @SCRIPTSAG
    @SCRIPTSAG Před 4 lety +1

    Array tak ke problems enough hai

  • @coolwithsaquibaquib
    @coolwithsaquibaquib Před 5 lety +1

    why 4 is not leader

    • @mohamedlamnaouar2175
      @mohamedlamnaouar2175 Před 5 lety +1

      because 5 is greater than for 4, and position the number 5 is right of 4, so 4 is not the leader

  • @nikhillingam4630
    @nikhillingam4630 Před 6 lety

    good