gary@interview:~/interview/coding/941-valid-mounta….md$
$ cat ./coding/941-valid-mountain-array.md
[Coding]

941. Valid Mountain Array

────────────────────────────────────────────────────────────

941. Valid Mountain Array

class Solution:
    def validMountainArray(self, arr: List[int]) -> bool:
        peak = 0
        n = len(arr)

        # Climb to the peak 
        for i in range(1, n):
            if arr[i] > arr[i - 1]:
                peak = i
            else:
                break

        # Climb to the peak 
        # - peak == 0: the starting point is the peak
        # - peak == n - 1: the ending point is the peak
        if peak == 0 or peak == n - 1:
            return False

        # Keep climbing to the end
        for i in range(peak, n - 1):
            # if next point is larger then current point, it goes up again. 
            if arr[i] <= arr[i + 1]:
                return False

        return True
--tags#Array
$ ls ./coding/ | grep -v 941-valid-mountain-array
265. Paint House II256. Paint House143. Reorder List1762. Buildings With an Ocean View
← cd ../codingcd ~