@@ -0,0 +1,829 @@
+package ds.arrays;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Find all the leaders in a given array. A leader (a%5Bi%5D) is an element in which %0A * a%5Bi%5D%3E a%5Bj%5D, and j%3Ei.%0A * %0A * @author bboggaramrama%0A *%0A */%0Apublic class A14LeadersinArray %7B%0A%09%0A%09public static void main(String args%5B%5D) %7B%0A%09%09A14LeadersinArray driver = new A14LeadersinArray();%0A%09%09driver.findLeader(new int%5B%5D %7B16,17,4,3,5,2%7D);%0A%09%7D%0A%09%0A%09/**%0A%09 * The idea here is that you iterate from right side of the array. %0A%09 * Keep a max so far you have seen till now. %0A%09 * @param a%0A%09 */%0A%09public void findLeader(int%5B%5D a) %7B%0A%09%09int n = a.length - 1;%0A%09%09int max = a%5Bn%5D;%0A%09%09int%5B%5D leaders = new int%5Bn%5D;%0A%09%09int k =0;%0A%09%09leaders%5Bk++%5D = a%5Bn%5D;%0A%09%09for (int i = n; i %3E= 0; i--) %7B%0A%09%09%09if(max %3C a%5Bi%5D) %7B%0A%09%09%09%09leaders%5Bk++%5D = a%5Bi%5D;%0A%09%09%09%09max = a%5Bi%5D;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09System.out.println(%22Leaders : %22 + Arrays.toString(leaders));%0A%09%7D%0A%0A%7D%0A

Find leaders in a given array of integers