let min_jumps arr =
  let n = Array.length arr in
  if n <= 1 then 0
  else begin
    let jumps = ref 0 in
    let cur_end = ref 0 in
    let farthest = ref 0 in
    let i = ref 0 in
    while !i < n - 1 do
      if !i + arr.(!i) > !farthest then farthest := !i + arr.(!i);
      if !i = !cur_end then begin
        jumps := !jumps + 1;
        cur_end := !farthest
      end;
      i := !i + 1
    done;
    !jumps
  end

;;

min_jumps [| 2; 3; 1; 1; 2; 4; 2; 0; 1; 1 |]
