We ca use HashSet data structure to remove duplicats from an array in O(n) time. HashSet does not allow duplicate elements. So add all elements from an array to HashSet. While adding first check whether current element is already in Set or not. If it is already there then remove from an array. PSUDO CODE: void removeDuplicateFromArray(int []array, int size): 1. create a HashSet: HashSet set = new HashSet(); 2. Itereate give array and add element in Set one by one: int k = 0; for i=0 to size-1: if(!set.contains(array[i]) // if current element is not in Set, then add it in set and include in array also array[k++] = array[i]; set.add(array[i]) Runnning TIme: O(n) Solution We ca use HashSet data structure to remove duplicats from an array in O(n) time. HashSet does not allow duplicate elements. So add all elements from an array to HashSet. While adding first check whether current element is already in Set or not. If it is already there then remove from an array. PSUDO CODE: void removeDuplicateFromArray(int []array, int size): 1. create a HashSet: HashSet set = new HashSet(); 2. Itereate give array and add element in Set one by one: int k = 0; for i=0 to size-1: if(!set.contains(array[i]) // if current element is not in Set, then add it in set and include in array also array[k++] = array[i]; set.add(array[i]) Runnning TIme: O(n).