mistakes in java

 // Online Java Compiler

// Use this editor to write, compile and run your Java code online


class Main {

    public static void main(String[] args) {

       int [] arr = {16, 17, 4, 3, 5, 2};

       int [] leader=new int[arr.length];

       int index=0;

       

for(int i=arr.length-1;i>0;i--){

    for(int j=i-1;j>=0;j--)

    if(arr[i]>arr[j]){

        leader[index++]=arr[i];

    }

}

leader[0]=arr[arr.length-1];

for(int ele:leader){

    System.out.println(ele);

}

    }

}

Comments

Popular posts from this blog

optimsed apporach

what i learn

creative codes