Day1: (Arrays)

  1. Find the duplicate in an array of N integers. Solved on: 15th July 2020

def findDuplicate(self, nums: List[int]) -> int:
    l=[]
    for item in nums:
        if item in l:
            return (item)
        else:
            l.append(item)

2. Sort an array of 0’s 1’s 2’s without using extra space or sorting algo Looked for answer: 15th July 2020

def sortColors(self, nums: List[int]) -> None:
    # Point at the last 0
    l=0
    r=len(nums)-1
    curr=0
    while (curr<=r):
        if (nums[curr]==0):
            nums[l], nums[curr] = nums[curr], nums[l]
            l=l+1
            curr=curr+1
        elif (nums[curr]==2):
            nums[curr], nums[r] = nums[r], nums[curr]
            r=r-1
        else:
            curr=curr+1
            

3. Repeat and Missing Number Looked for answer on: 15th July 2020

4. Merge two sorted Arrays without extra space Looked for answer on 16th July 2020

5. Kadane’s Algorithm Looked for answer on: 16th July 2020

6. Merge Overlapping Sub intervals Looked for answer on: 16th July 2020

Last updated

Was this helpful?