package leetcode;

/**
 * https://leetcode.com/problems/valid-mountain-array/
 */
public class Problem941 {
    public boolean validMountainArray(int[] A) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem941 prob = new Problem941();
        System.out.println(prob.validMountainArray(new int[]{2, 1})); // false
        System.out.println(prob.validMountainArray(new int[]{3, 5, 5})); // false
        System.out.println(prob.validMountainArray(new int[]{0, 3, 2, 1})); // true
        System.out.println(prob.validMountainArray(new int[]{0, 3, 2, 1, 5})); // false
        System.out.println(prob.validMountainArray(new int[]{3, 5, 5, 2})); // false
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/valid-mountain-array/
 */
public class Problem941 {
    public boolean validMountainArray(int[] A) {
        if (A.length <= 2) {
            return false;
        }
        boolean increasing = true;
        boolean decreasing = false;
        for (int i = 0, j = 1; j < A.length; i++, j++) {
            if ((increasing && A[i] >= A[j]) ||
                (decreasing && A[i] <= A[j])) {
                return false;
            }
            if (A[i] < A[j]) {
                if (j + 1 < A.length && A[j] > A[j + 1]) {
                    increasing = false;
                    decreasing = true;
                }
            }
        }
        return !increasing && decreasing;
    }
}

Solve problem 941