Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed Competitive Coding 1 #1060

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def binarySearchmis(arr, l ,h) -> int:
while (l<=h):
mid = (l + h)//2
if mid ==len(arr)-1 or (mid == arr[mid]-1 and mid + 1 == arr[mid+1] - 2):
return arr[mid] + 1
if mid == 0 or (mid == arr[mid] - 2 and mid - 1 == arr[mid-1] - 1):
return arr[mid] - 1
elif mid < arr[mid] - 1:
return binarySearchmis(arr, l, mid-1)
else:
return binarySearchmis(arr, mid+1, h)
return arr[h]+1


arr= [2,3,4]

print(binarySearchmis(arr,0,len(arr)-1))
40 changes: 40 additions & 0 deletions Problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class minHeap:
def __init__(self):
self.heap = []
self.size = 0
def insert(self, data: int) -> None:
self.heap.append(data)
self.size += 1
i = len(self.heap) - 1
while (i //2 >= 0):
if self.heap[i] < self.heap[i//2]:
self.heap[i], self.heap[i//2] = self.heap[i//2], self.heap[i]
else:
break
i = i // 2
def removemin(self) -> int:
if not self.heap:
return
i = 0
while(i*2 < len(self.heap)-1):
self.heap[i], self.heap[2*i + 1] = self.heap[2*i + 1], self.heap[i]
i = 2*i + 1
return self.heap.pop()
def getmin(self) -> int:
if not self.heap:
return
return self.heap[0]


Heap = minHeap()

Heap.insert(3)
Heap.insert(2)
Heap.insert(1)

print(Heap.getmin())

print(Heap.removemin())

print(Heap.removemin())