Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Loop through each middle element and compare it to the element after. If it's larger than the next element, we've found the peak.
1) Loop through the middle elements of the list (skip the beginning/end)
2) Compare each element to the next element
a) If the next element is bigger, keep looking
b) If the next element is smaller, return the current element
def peak_index_in_mountain_list(lst):
for i in range(1, len(lst) - 1):
if lst[i] > lst[i + 1]:
return i