Suppose we have a list of numbers called nums of size n where all numbers in the list are present in the interval [1, n] some elements may appear twice while others only once. We have to find all of the numbers from [1, n] such that they are not in the list. We have to return the numbers sorted in ascending order. We have to try to find a solution that takes linear time and constant space.
So, if the input is like [4, 4, 2, 2, 6, 6], then the output will be [1, 3, 5].
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, nums): arr = *(len(nums)+1) for i in nums: arr[i] += 1 missing =  for i in range(len(arr)): if arr[i] == 0 and i != 0: missing.append(i) return missing ob = Solution() print(ob.solve([4, 4, 2, 2, 6, 6]))
[4, 4, 2, 2, 6, 6]
[1, 3, 5]