Leaders in an array | GeeksforGeeks

Поділитися
Вставка
  • Опубліковано 30 вер 2024

КОМЕНТАРІ • 28

  • @wecan2729
    @wecan2729 3 роки тому +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;
    }

  • @kvenkatasivareddy5812
    @kvenkatasivareddy5812 5 років тому +3

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

  • @apoorvgarg0204
    @apoorvgarg0204 4 роки тому +3

    Thank you so much for these videos!

  • @suryakantsapkal8242
    @suryakantsapkal8242 4 роки тому +3

    Nicely explained!! Kudos to GFG team🙌

    • @Thowfi
      @Thowfi 2 роки тому

      Rtmgtreghgyhfserk.jwro-

    • @Thowfi
      @Thowfi 2 роки тому

      dsoee]yrttyra;/htupiutdufffffifd;uesrsssdiugyyfpfdihoffo\==

    • @Thowfi
      @Thowfi 2 роки тому

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

  • @sudipmahata8346
    @sudipmahata8346 5 років тому +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 4 роки тому +1

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

    • @lucky_raiser
      @lucky_raiser 4 роки тому

      @@abhishekaman708 but still it is not optimized.

  • @sonusingh-hj2dw
    @sonusingh-hj2dw 4 роки тому +1

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

  • @SCRIPTSAG
    @SCRIPTSAG 4 роки тому +1

    Array tak ke problems enough hai

  • @abhijeetjain2098
    @abhijeetjain2098 5 років тому +1

    this code is not giving output in java..

    • @musicquotes5357
      @musicquotes5357 5 років тому

      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];
      }
      }
      }
      }

  • @archanaprakash1107
    @archanaprakash1107 4 роки тому

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

  • @reyou7
    @reyou7 7 років тому +2

    very good, thank you!

  • @coolwithsaquibaquib
    @coolwithsaquibaquib 5 років тому +1

    why 4 is not leader

    • @mohamedlamnaouar2175
      @mohamedlamnaouar2175 5 років тому +1

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

  • @sangnguyenn2367
    @sangnguyenn2367 2 роки тому

    Thank you so much

  • @ShubhamMishra-mz4zw
    @ShubhamMishra-mz4zw 4 роки тому

    Thanks a lot gfg...

  • @hermesmercuriustrismegistu4841
    @hermesmercuriustrismegistu4841 4 роки тому

    thx a lot

  • @nikhillingam4630
    @nikhillingam4630 7 років тому

    good