---
# System prepended metadata

title: Untitled

---

# 

# Coding Test 

# Question 1
```
Given an array of random positive numbers, move all the zeroes to the left of the array. 

Conditions: 
1) has to be done in place ( space-constrained, ie. cannot allocate a new array)
2) the order of non-zero elements on the right do not matter

Input :  arr[] = {0, 1, 2, 5, 0, 3, 0, 3};
Output : arr[] = {0, 0, 0, 2, 1, 3, 3, 5};
```


```javascript / ruby / go / python
// Write your solution here
function pushZero(a) {
    if (a.length <= 1) return a;
    let posSwapLeft = 0;
    let i = 1;
    
    while (i < a.length) {
        if (a[i] == 0) {
            //find the position to swap:
            while (a[posSwapLeft]==0 && posSwapLeft < i){
                posSwapLeft++;
            }
                
            if (i > posSwapLeft) {
                a[i] = a[posSwapLeft];
                a[posSwapLeft] = 0;
            }
        }
        i++;
    }
}


// a = {0, 1, 2, 5, 0, 3, 0, 3};
// i 1:
//     posSwapLeft=0 -> 1:   {0, 1, 2, 5, 0, 3, 0, 3};
// i 2:
//    posSwapLeft = 1













