/* Given array is already sorted, and it has duplicate elements. Write a program to remove duplicate elements and return new array without any duplicate elements. The array should contain only unique elements. */ public class MyDuplicateElements { public static int[] removeDuplicates(int[] input) { int j = 0; int i = 1; //return if the array length is less than 2 if(input.length < 2) { return input; } while(i < input.length) { if(input[i] == input[j]) { i++; } else { input[++j] = input[i++]; } } int[] output = new int[j+1]; for(int k=0; k