> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/06-05-2022-941.-valid-mountain-array.md).

# 06/05/2022 941. Valid Mountain Array

Method: imagine two people climbing the mountain from the left and right sides. If the mountain is valid, they can reach the same index. So lets the left people first climb. While the l+ 1 < N and arr\[l] < arr\[l+1], we increment index l. After the while loop, we check if the index l is not 0 or it is not N. Then we let the right people climb, we need to check if the arr\[right] is less than the arr\[right-1]. Finally return l == right.

Time O(N)

Space O(1)

```
// Some code
class Solution {
    public boolean validMountainArray(int[] arr) {
        if (arr.length < 3) return false;
        int lo = 0;
        int N = arr.length - 1;
        int high = N;
        while (lo + 1 < N && arr[lo] < arr[lo+1]) lo++;
        if (lo == 0 || lo == N) return false;
        
        while (high - 1 > 0 && arr[high] < arr[high - 1]) high--;
        if (high == N) return false;
        return lo == high;
        
    }
}
```
