class Solution { public List findDisappearedNumbers(int[] nums) { for(int i=0; i< nums.length;){ int element = nums[i]-1; if(nums[i]!=nums[element]){ // swap int temp = nums[i]; nums[i]=nums[element]; nums[element]=temp; }else{ i++; } for(int l=0; l ans = new ArrayList(); for(int j=0; j < nums.length; j++){ System.out.println(nums[j]); if(nums[j]!=j+1){ ans.add(j+1); } } return ans; } } Result Input: [4,3,2,7,8,2,3,1] 7 3 2 4 8 2 3 1 3 3 2 4 8 2 7 1 2 3 3 4 8 2 7 1 3 2 3 4 8 2 7 1 3 2 3 4 8 2 7 1 3 2 3 4 8 2 7 1 3 2 3 4 8 2 7 1 3 2 3 4 8 2 7 1 3 2 3 4 1 2 7 8 1 2 3 4 3 2 7 8 1 2 3 4 3 2 7 8 1 2 3 4 3 2 7 8 1 2 3 4 3 2 7 8 1 2 3 4 3 2 7 8 1 2 3 4 3 2 7 8 Output: [5,6]