<p>You are given an integer <strong>mountain</strong> array <code>arr</code> of length <code>n</code> where the values increase to a <strong>peak element</strong> and then decrease.</p>

<p>Return the index of the peak element.</p>

<p>Your task is to solve it in <code>O(log(n))</code> time complexity.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">arr = [0,1,0]</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">arr = [0,2,1,0]</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">arr = [0,10,5,2]</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>3 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= arr[i] &lt;= 10<sup>6</sup></code></li>
	<li><code>arr</code> is <strong>guaranteed</strong> to be a mountain array.</li>
</ul>

"""
we can see it as a slope problem

cases:
- length of the array = 1
- 1, 2, 3, 4, 4, 3, 2
-  1, 2, 3, 4
-  4, 3, 2, 1
slope + + + +, ---
"""


class Solution:
    def peakIndexInMountainArray(self, arr: List[int]) -> int:
        """
        possible clarifications,
        array length; what about 'monotonically' increasing or monotonically decreasing 
        does that count as a mountain array as well
        would it be possible to have consecutive numbers that are equal

        0, 8, 4, 2
        +  +  -  -
        8 4 2
        + - - 
        2 4 8
        + + +
        """
        start, end = 0, len(arr) - 1
        while (start + 1) < end:
            mid = start + (end - start) // 2
            if self.meet_condition(arr, mid):
                start = mid
            else:
                end = mid
        
        if self.meet_condition(arr, end):
            return end 
        if self.meet_condition(arr, start):
            return start 
        return -1


    def meet_condition(self, arr, index):
        return index == 0 or (arr[index] >= arr[index-1])
30900