Skip to content

Commit

Permalink
Heap -- Adds function to check Max_Heap in array - return max incase …
Browse files Browse the repository at this point in the history
…true / or the false node
  • Loading branch information
esl4m committed Feb 28, 2021
1 parent 2dd78a3 commit 1607f96
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Data_Structures/heap/max_heap_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def MaxHeapChecker(arr):

# code goes here
res = [] # array of wrong elements
n = len(arr)

for i in range(n//2):
if arr[i*2+1] > arr[i]:
res.append(str(arr[i*2+1]))

if 2*i+2 < n and arr[i*2+2] > arr[i]:
res.append(str(arr[i*2+2]))

return ",".join(res) if len(res) else 'max'

# keep this function call here
print(MaxHeapChecker(input()))

0 comments on commit 1607f96

Please sign in to comment.