educative.io

Solution does not work when the input list does not contain duplicates

print(find_missing_numbers([6, 1, 2, 4, 5]))

File “main.py”, line 5, in find_missing_numbers
if nums[i] != nums[j]:
IndexError: list index out of range

Line #5 in python code should be - if j < len(nums) and nums[i] != nums[j]: to fix the issue reported

Best way for all array problems is to always check below 2 cases and return as needed.
//For JAVA
int[] nums = {1,2,3,4,5};

if(num==null || nums.length==0)
return -1; //OR return null //whatever is needed.

##For Python.
if not nums:
print(‘nums List is empty’)
return nums;

OR
if len(nums)==0:
print(‘nums List is empty’)
return nums
OR
if nums==[]:
print(‘nums List is empty’)
return nums