Computer Science, asked by sahir3446, 1 year ago

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