forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrogJmp.py
More file actions
30 lines (26 loc) · 837 Bytes
/
frogJmp.py
File metadata and controls
30 lines (26 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Codility Problem - FrogJumps
# (X,Y,D) - Frog can jump D at a time, starting from X and goal is to reach Y or greater than Y.
# Solution Logic:
# Y-X as X is the starting point
# Y-X // D to get the quotient or number of times to divide it by D
# Y-X % D to get the reminder if any
# Until reminder is 0 or lesser add jumps and subtract D every time
def solution(X, Y, D):
### Solution passed all the cases with complexity O(N)
value = Y-X
jumps = value//D
reminder = value%D
while reminder > 0:
jumps += 1
reminder = reminder - value
return jumps
#### Only 11% Pass
"""
jumps = Y//D
reminder = (Y-X)%D
value = reminder//D
#print(jumps,reminder,value)
if reminder > 0 and reminder < D:
value = 1
return jumps + value
"""