---
# System prepended metadata

title: Name

---


# Name

# 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];
```

```php
// Write your solution here

$len = count($arr);
for($i=0; $i<$len; $i++){
    if($arr[$i]==0){
        continue;
    }
    
    $tmp = $arr[$i];
    unset($arr[$i]);
    array_push($arr, $tmp);
}




```

# Question 2
```
//        1 <---- root
//     /     \
//    2       3
//   / \     / \
//  4   5   6   7 
//
// 1) create the node type
// 2) write a function to print tree by level 
// ie. print "1","2","3","4","5","6","7"....
```



```php
class Tree {
    public $val=null;
    public $left=null;
    public $right=null;
    function __construct($val=0, $left=null, $right=null){
        $this->val = $val;
        $this->left = $left;
        $this->right = $right;
    }
}


function printer($tree){
    $arr = [];
    array_push($arr,$tree);
    
    foreach($arr as $node){
        echo $node->val.",";
        if($node->right)
            array_push($arr, $node->right);
        if($node->left)
            array_push($arr, $node->left);
    }
}




























```

