An element in an array x is called a leader if it is greater than all elements to the right of it in x. The best algorithm to find all leaders in an array. A
Answers
Answered by
0
Answer:
class prog
{ void main(int a[])
{int l= a.length();
for(int i=0;i<l;i++)
{if(i==l)
{System.out.println(a[i]+"is a leader") ;
continue;}
int y=0;
for(int j=i+1;j<l;j++)
{
if(a[j]>a[i])
{y=1;}
}
if(y==0)
{ System.out.println(a[i]+" is a leader);}
}
}}
hope this helps you
i have put in quite an effort typing this on my phone.
Please mark it as the brainliest answer.
Similar questions
Math,
6 months ago
History,
6 months ago
Social Sciences,
6 months ago
CBSE BOARD X,
1 year ago
Science,
1 year ago