Please help me 1 TC fail

package Challenges06_StackAndQueues;

import java.util.Scanner;
import java.util.Stack;

public class App06_FindTheGreaterElement {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] arr = new int[N];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
Stack stack = new Stack();

	for (int i = 0; i < arr.length; i++) {
		if (stack.isEmpty()) {
			stack.push(arr[i]);
		} else if (!stack.isEmpty() && arr[i] > stack.peek()) {
			System.out.print(arr[i]+" ");
			stack.pop();
			stack.push(arr[i]);
		}
		else if(arr[i]<=stack.peek()) {
			System.out.print(-1+" ");
			stack.pop();
			stack.push(arr[i]);
		}
	}
	while(!stack.isEmpty()) {
		System.out.print(-1+" ");
		stack.pop();
	}
}

}

Consider a test case:
5
7 3 4 5 2
correct output : -1 4 5 7 7

refer to this approach here