Two pointer

Time complex O(n) Space complex O(1) a Sorted array

Leetcode 977

class Solution(object):
    def sortedSquares(self, A):
        """
        :type A: List[int]
        :rtype: List[int]
        """
        length = len(A)
        leftPointer = 0
        rightPointer = length-1

        result = []
        while(leftPointer <= rightPointer):
            leftData = A[leftPointer]*A[leftPointer]
            rightData = A[rightPointer]*A[rightPointer]
            if leftData >= rightData:
                result.insert(0,leftData)
                leftPointer +=1
            else:
                result.insert(0,rightData)
                rightPointer -=1
        return result

Leetcode 448

class Solution(object):
    def findDisappearedNumbers(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        if not nums:
            return 
        
        start = 0
        while start < len(nums):
            num = nums[start]-1
            if num < len(nums) and num != start and nums[num] != nums[start]:
                nums[start], nums[num] = nums[num], nums[start]
            else:
                start += 1
        
        r = []
        for i in range(len(nums)):
            if nums[i] != i+1:
                r.append(i+1)
                
        return r
``