Whats the error in this

import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();

	int[] arr = new int[n];
	for(int i=0;i<n;i++){
		arr[i] = sc.nextInt();
	}

	Stack<Integer> stack = new Stack<>();
	
	for(int i=0;i<arr.length;i++){

		while(!stack.isEmpty()){
			if(stack.peek() > arr[i]){
				System.out.print(arr[i]+" ");
				stack.pop();
			}
		
		}
		stack.push(arr[i]);
	}

	while(!stack.isEmpty()) {
		int rv = stack.pop();
		System.out.println(rv+" ");
	}
}

}

Hey @ParagKumar,
You are provided with a circular array and your code is considering just a 1-D array.
Try incorporating the case of Circular Array

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.