#102 Moving Zeros to the End of an Array

Companies:
OTP Bank
Themes:
AlgorithmsArraysPractice

An array containing numbers, including zeros, is given. Without creating new arrays, move all zeros to the end of the array:

public class Main {
    public static void main(String[] args) {
        int[] nums = {0, 1, 0, 3, 12};
        moveZerosToEnd(nums);
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }

    public static void moveZerosToEnd(int[] nums) {
        ...
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in