Recover the Arrays

  • [deleted]
    + 0 comments

    php solution

    <?php
    
    $handle = fopen ("php://stdin","r");
    fscanf($handle,"%d",$n);
    $file = array_map("intval", explode(" ",fgets($handle)));
    
    $i = 0;
    $s = 0;
    while($i < $n) {
        $i += ($file[$i] + 1);
        $s++;
    }
    echo $s;
    
    ?>