1 TC Failed please help

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int N = scanner.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
your code gives : 4 5 -1 -1 -1

debug your code for this

my half output is right for this TC-> 7 3 4 5 2 my OP is coming this -1 4 5 -1 -1 and you’re telling my OP is coming this 4 5 -1 -1 -1 pls tell me what is the wrong with my code

for this TC 7 3 4 5 2 how this OP 4 5 -1 -1 -1 is coming and my OP is coming this -> -1 4 5 -1 -1

refer to this approach here