Can't figure out the mistake :(


#1

Can somebody help me in identifying the mistake in this code! Please.

import java.util.Stack;
public class Solution {
public ArrayList prevSmaller(ArrayList input) {
ArrayList output = new ArrayList<>();
Stack stack = new Stack<>();
stack.push(input.get(0));
output.add(-1);

  for(int i=1;i<input.size();i++){
        int temp = stack.peek();
        if(input.get(i) >= temp){
            output.add(stack.peek());
            stack.push(input.get(i));
            continue;
        }
        else{
            while(input.get(i)<stack.peek() && !stack.isEmpty()){
                stack.pop();
                if(stack.size()==0){
                    output.add(-1);
                    stack.push(input.get(i));
                    continue;
                }
            }
            output.add(stack.peek());
            stack.push(input.get(i));
        }
    }
    return output;
}

}