https://app.codility.com/programmers/lessons/3-time_complexity/frog_jmp/

 

FrogJmp coding task - Learn to Code - Codility

Count minimal number of jumps from position X to Y.

app.codility.com

 

  • X 현재 위치
  • Y 도착 위치
  • D 점프 길이
  • X에서 Y로 갈 때, 점프 횟수 구하기
  • O(1)

 

def solution(X, Y, D):
    distance = Y-X
    if distance % D ==0:
        return distance//D
    return int(distance//D)+1

+ Recent posts