Bug Report - Missing Edge Case


  • 0
    D
    public static void moveToEnd(int[] array,int length,int index){
        for(int i = index;i < length;i++){
            int temp = array[i + 1];
            array[i + 1] = array[i];
            array[i] = temp;
        }
    }
    public void moveZeroes(int[] nums) {
        int n = nums.length - 1;
        
        if(nums == null || n == 0){
            return;
        }
    
        for(int i = 0;i < n;i++){
            if(nums[i] == 0){
                moveToEnd(nums,n,i);
            }
        }
        for(int j = 0;j < n;j++){
            if(nums[j] == 0){
                moveToEnd(nums,n,j);
            }
        }
    }
    

    My solution is accepted but i have found an edge case that you should add.
    The test case:

    [0,0,0,0,1]
    It seems that for every copy and paste of the loop i can add 2^(number of loops) - 1 zeroes then a non negative integer and still get accepted but when i go (2^number of loops) of zeroes then a non negative integer i get different solutions to the accepted one.
    I propose that you add a test case of the max number of elements in array - 1 of zeroes then a non negative integer as a test case.
    so [0..(max number -1),1].
    First time posting so dunno if i'm posting like an idiot.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.