Why am i getting varied faster than x percent for different submissions for the same code.

So i was solving this question

class Solution {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        
        Stack <Integer> stack = new Stack<Integer>();
        int p1 = 0, p2 = 0;
        int n = pushed.length;
        int j = 0;
        for(int i = 0 ; i<n; i++) {
            
            stack.push(pushed[i]);
            
            while(!stack.isEmpty() && stack.peek() == popped[j]){
                j++;
                stack.pop();
            }
            
            
        }
        
        
        return stack.isEmpty();
        
    }
}```
And i was submitting this solution and for this piece of code itself i was getting the values for faster than x where x was from 15% to 90 %.
Kind of baffled as i use this metric to often optimize my code and i try to bring as close to 99 as possible. Any help would be appreciated.
Comments (1)