Increasing decreasing sequence query

cannot find any error but 2 test cases from 9 are failing

import java.util.Scanner;

public class Increasing_Decreasing_Sequence {

public static void main(String[] args) {

	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();

	int[] a;
	a = new int[n];
	for (int i = 0; i < n; i++) {
		a[i] = scan.nextInt();
	}
	if (a[1] >= a[0]) {
		for (int i = 1; i < n - 1; i++) {
			if (a[i] == a[i - 1]) {
				System.out.println("false");
				return;
			}
			if (a[i] < a[i - 1]) {
				if (a[i] < a[i + 1]) {
					System.out.println("false");
					return;
				}
			}
		}
	} else {
		for (int i = 1; i < n - 1; i++) {
			if (a[i] == a[i - 1]) {
				System.out.println("false");
				return;
			}
			if (a[i] > a[i - 1]) {
				if (a[i] > a[i + 1]) {
					System.out.println("false");
					return;
				}
			}
		}
	}
	if (a[n - 1] == a[n - 2]) {
		System.out.println("false");
	} else
		System.out.println("true");

}

}