Competitive Programming Solutions

GitHub
back to dashboard

B. Reversing

Codeforces - Contest #3.1 · limit: 1s · memory: 256MB · view on codeforces

input

7
1 2 0 4 0 5 6

output

4 0 1 2 0 5 6
Main.java
static void solve() {

        // Write your solution here
        int n = in.nextInt();
        int[] a = readIntArray(n);
        for(int i = 0; i < n; i++){
            if(a[i] == 0)
                reverse(a, i - 1);
        }
        for(int i: a){
            out.print(i + " ");
        }
    }