---
# System prepended metadata

title: CommonEdge Interview with Miroslav

---

# CommonEdge Interview with Miroslav

### If you could program in any language, what would it be?

### Why doesn't 0.4 + 0.8 == 1.2? (in javascript, Java, PHP, C, etc.)


### Fix the bugs in this function to count reachable nodes in a directed graph.

```php
class Node {
    public $value;
    public $children; // : Node[]
    
    // count how many nodes are reachable from this node including this node
    public countNodes($seen=[]) {
        $n = 1;
        foreach($this->children as $child) {
            if (!in_array($child, $seen)) {
                $seen[] = $child;
                $n += $child->countNodes(&$seen);
            }
        }
        return $n;
    }
}
```

### Given an array of numbers, return the second greatest number without using sort.

```php=
function max2($nums) {


    if (2 > count($nums)) {
         echo 'Error';                    
    }
    $biggest = $nums[0];
    foreach($nums as $num) {
        if ($num > $biggest) {
            $biggest = $num;
        }    
    }

    $secondBiggest = ($biggest != $nums[0]) : $nums[0] ? $nums[1];
    foreach($nums as $num) 
        if ($num > $secondBiggest && $num != $biggest) {
            $secondBiggest = $num;
        }
    }

    return $secondBiggest;
}

max2([0,1,1]);


```

### Discuss advantages vs disadvantages of (more complicated versions of)

```javascript
const max = a > b ? a : b;
```

    vs.
    
```javascript
const max = Math.max(a,b);
```
