Розмір відео: 1280 X 720853 X 480640 X 360
Показувати елементи керування програвачем
Автоматичне відтворення
Автоповтор
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; }
Thank you so much👍🏻
is there only one leader in the array or multiple leaders ?
multiple
Thank you so much for these videos!
Nicely explained!! Kudos to GFG team🙌
Rtmgtreghgyhfserk.jwro-
dsoee]yrttyra;/htupiutdufffffifd;uesrsssdiugyyfpfdihoffo\==
Sh'py]\uugv,'i1[pr vn ch;yo[to]--
actual answer of the question is - 17 5 2when 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.
Despite printing it, Store the values in a vector. Return the vector and print it in reverse order.
@@abhishekaman708 but still it is not optimized.
In the linear time algo discussed,it will print the element in reverse order .
Array tak ke problems enough hai
this code is not giving output in java..
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]; } } }}
How to count the leaders in an arrayAs per my question the answer should be 3 .As there are 3 leaders.
very good, thank you!
Thanks reyou7!
why 4 is not leader
because 5 is greater than for 4, and position the number 5 is right of 4, so 4 is not the leader
Thank you so much
Thanks a lot gfg...
thx a lot
good
Thanks NIKHIL LINGAM
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;
}
Thank you so much👍🏻
is there only one leader in the array or multiple leaders ?
multiple
Thank you so much for these videos!
Nicely explained!! Kudos to GFG team🙌
Rtmgtreghgyhfserk.jwro-
dsoee]yrttyra;/htupiutdufffffifd;uesrsssdiugyyfpfdihoffo\==
Sh'py]\uugv,'i1[pr vn ch;yo[to]--
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.
Despite printing it, Store the values in a vector. Return the vector and print it in reverse order.
@@abhishekaman708 but still it is not optimized.
In the linear time algo discussed,it will print the element in reverse order .
Array tak ke problems enough hai
this code is not giving output in java..
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];
}
}
}
}
How to count the leaders in an array
As per my question the answer should be 3 .
As there are 3 leaders.
very good, thank you!
Thanks reyou7!
why 4 is not leader
because 5 is greater than for 4, and position the number 5 is right of 4, so 4 is not the leader
Thank you so much
Thanks a lot gfg...
thx a lot
good
Thanks NIKHIL LINGAM