Amazon Interview Question
Applications DevelopersCountry: India
public static void main(String args[]) {
int[] a = {1,3,4,7,11,18,0,2,5,8,21,25};
int mid = a.length/2;
int i = 0, j = mid;
while (i < mid && j < a.length) {
System.out.println(a[i] < a[j]? a[i++]: a[j++]);
}
if (i == mid)
while (j < a.length)
System.out.println(a[j++]);
else
while(i < mid)
System.out.println(a[i++]);
}
Take two pointers pointing to first and second half ..Compare the elements present..in them
- Lucy Desouza October 31, 2012..Output/ print the one which is smallest and increment its index pointer..and keep the other index pointer as it is ..run the loop till the all the elements are Exhausted / printed :)