# Help me in solving AOJ05 problem

### My code

``````// Update the '_' in the code below to solve the problem
import java.util.*;
class Codechef
{
public static void main (String[] args)
{
int ele;
for(int i=0; i<t; i++)
{
ArrayList<Integer> a = new ArrayList<Integer>();
for(int j=0; j<n; j++){
// Read elements from the user and add it to the ArrayList
}

// We first find the smallest element, and which index it is in.
int minElement = a.get(0);
int minElementIndex = 0;
int l = 1;
while(l<n){
if(a.get(l) < l){
// If we find an element smaller than the previous smallest, we update
minElement = a.get(l);
minElementIndex = l;
}
l++;
}
// We are starting the operation from index of the smallest element
int k = minElementIndex;
while(k > 0){
// Swap the elements at position k and k-1
Collections.swap(a, k, k-1);
k = k-1;
}
for(int x=0; x<n; x++){
// Print the elements of the ArrayList
System.out.print(a.get(x) + " ");
}
System.out.print("\n");
}
}
}
``````

Learning course: Placement preparation using Java
Problem Link: CodeChef: Practical coding for everyone

You will just have to change your if condition in finding the minElement.
you should change
while(l<n){
if(a.get(l) < l){
// If we find an element smaller than the previous smallest, we update
minElement = a.get(l);
minElementIndex = l;
}
l++;
}
to
while(l<n){
if(a.get(l) < minElement){
// If we find an element smaller than the previous smallest, we update
minElement = a.get(l);
minElementIndex = l;
}
l++;
}
easy