So close but just off base. What am I doing wrong? Java

I'm so close but don't know what I've done wrong. Here's my code:

class Solution {
    public int[] sortedSquares(int[] nums) {
        int back = 0;
        int front = nums.length - 1;
        int[] result = new int[nums.length];
        
            while(nums[back] < 0){
                if(Math.abs(nums[back]) > nums[front]){
                    result[front] = nums[back] * nums[back];
                    back++;
                }else{
                    result[front] = nums[front] * nums[front];
                    front--;
                }
            }
        for(int i = back; i < front; i++){
            result[i] = nums[back];
            back++;
        }
        
        return result;
    }
}

It'll let the first element be 0, instead of whatever it was, and everything else will be in order, the right value, and work. Total number of values is same. What's going on here?

Comments (1)