Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.