Skip to content
Closed
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
23 changes: 23 additions & 0 deletions data_structures/arrays/peak_mountain_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
peak_mountain_array.py
Author: Taha Zulfiquar
Description: Finds the peak index in a mountain array using binary search.
"""


def peak_mountain(arr):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/peak_mountain_array.py, please provide doctest for the function peak_mountain

Please provide return type hint for the function: peak_mountain. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: arr

start, end = 0, len(arr) - 1

while start < end:
mid = start + (end - start) // 2
if arr[mid] > arr[mid + 1]:
end = mid
else:
start = mid + 1
return start


if __name__ == "__main__":
arr = [1, 2, 3, 5, 7, 8, 6, 3, 2]
peak_index = peak_mountain(arr)
print("The peak index is:", peak_index)