Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solution(a, d)
- return 0 if a.size < d
- length = a.size
- position = 0
- (1..(length * 2)).each do |time|
- allowed_raduis_data = a[position..([position+d-1, length].min)]
- max_jump_position = allowed_raduis_data.reverse.find_index{|el| el != -1 && (el-time) <= 0}
- next if max_jump_position.nil?
- position += allowed_raduis_data.size - max_jump_position
- return [time, length, a.max].min if length - position < d
- end
- -1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement