<p>Given an array of integers <code>arr</code>, return <em><code>true</code> if and only if it is a valid mountain array</em>.</p>

<p>Recall that arr is a mountain array if and only if:</p>

<ul>
	<li><code>arr.length &gt;= 3</code></li>
	<li>There exists some <code>i</code> with <code>0 &lt; i &lt; arr.length - 1</code> such that:
	<ul>
		<li><code>arr[0] &lt; arr[1] &lt; ... &lt; arr[i - 1] &lt; arr[i] </code></li>
		<li><code>arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code></li>
	</ul>
	</li>
</ul>
<img src="https://assets.leetcode.com/uploads/2019/10/20/hint_valid_mountain_array.png" width="500" />
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> arr = [2,1]
<strong>Output:</strong> false
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> arr = [3,5,5]
<strong>Output:</strong> false
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> arr = [0,3,2,1]
<strong>Output:</strong> true
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= arr.length &lt;= 10<sup>4</sup></code></li>
	<li><code>0 &lt;= arr[i] &lt;= 10<sup>4</sup></code></li>
</ul>

class Solution:
    def validMountainArray(self, arr: List[int]) -> bool:
        if len(arr) < 3:
            return False
        
        # A mountain array strictly increases, then strictly decreases until the end. Anything else fails.

        # i = 0           # Pointer
        # trend = ''      # This saves the trend of the previous step.
        # peaked = False  # This detects an inflection point.
        # while i+1 < len(arr):
        #     if arr[i+1] - arr[i] > 0 and trend != 'down' and not peaked:
        #         i += 1
        #         trend = 'up'
        #     elif arr[i+1] - arr[i] < 0 and trend == 'up' and not peaked:
        #         i += 1
        #         trend = 'down'
        #         peaked = True
        #     elif arr[i+1] - arr[i] < 0 and trend == 'down' and peaked:
        #         i += 1
        #     else:
        #         return False
        # return peaked and trend == 'down'

        # An alternative more efficient way is to enforce following one peak. Then check if we're at the 
        # end of the array.

        # Go up.
        i = 0
        
        while i+1 < len(arr) and arr[i+1] - arr[i] > 0:
            i += 1
        
        # Make sure the peak wasn't the first or last element.
        if i == 0 or i+1 == len(arr):
            return False
        
        # Go down.
        while i+1 < len(arr) and arr[i+1] - arr[i] < 0:
            i += 1
        
        # Check if we got to the bottom
        return i+1 == len(arr)
17400