Skip to content

Instantly share code, notes, and snippets.

@ahmadhasankhan
Created February 11, 2016 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadhasankhan/e30307ef747aee28f5e1 to your computer and use it in GitHub Desktop.
Save ahmadhasankhan/e30307ef747aee28f5e1 to your computer and use it in GitHub Desktop.
Frog Interview Problem
def solution(a, x, d)
  k = a.size
  position = 0
  if position+d >= x
    return 0;
  end

  (0..k).each do |i|
    if (a[i] - position) <= d
      position = a[i]
      if position+d >= x
        return i;
      end
    end
    -1
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment