From 38e4afdc5d8386737297876c910083d50dec2d93 Mon Sep 17 00:00:00 2001 From: RITIKA CHAUBE Date: Mon, 22 Jun 2026 16:34:11 -0400 Subject: [PATCH] Done CC-1 --- Problem1.py | 20 +++++++++++++++++ Problem2.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Problem1.py create mode 100644 Problem2.py diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 00000000..dfd60969 --- /dev/null +++ b/Problem1.py @@ -0,0 +1,20 @@ +# Problem 1 Find Missing Number in a sorted array +# Time Complexity: O(log N) where N denotes the number of elements in an array +# Space Complexity: O(1) + +def missingNumber(arr): + if arr[0] != 1: + return 1 + high=len(arr)-1 + low=0 + while low<=high: + mid=(low+high)//2 + if arr[mid]==mid+1: + low=mid+1 + else: + high=mid-1 + return low+1 + + +arr=[1,2,3,4,5,7,8,9] +print(missingNumber(arr)) \ No newline at end of file diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 00000000..024ffaa3 --- /dev/null +++ b/Problem2.py @@ -0,0 +1,65 @@ +# Problem 2 Design Min Heap +# Time Complexity: O(log N) for insert function where N is the no.of elements stored +# : O(log N) for extract_min function where N is the no.of elements stored +# : O(1) for get_min as we are directly looking for the min value +# Space Compelxity: O(1) as everything is happening in the same self.heap list + +class MinHeap: + def __init__(self): + self.heap=[] + + def _heapify_up(self,index): + while index > 0: + parent_index=(index-1)//2 + if self.heap[index]0 else None + + def _heapify_down(self,index): + length=len(self.heap) + while 2*index+1