Skip to content

Commit

Permalink
Merge pull request adityaarakeri#76
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivas-challa1 committed Oct 18, 2020
1 parent a1e6ab7 commit e010314
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Google/Target Number with Operations/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ needed to convert start to end using these operations:
</p>
<ul>
<li>Increment by 1</li>
<li>Multiply by 2</li>
<li>Multiply b 2</li>
</ul>

<h3><b>Constraints</b></h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Approach:
start from the end given if the end is odd then perform 2 operations simultaneously decrement end by 1 and divide end with 2 else
divide end with 2 if it is even continuously perform these operations until end equals start
"""

def solve(start,end):
count=0
while(end//2>=start):
if(end%2==1):
end-=1
end//=2
count+=2
else:
end//=2
count+=1
count+=end-start
return(count)
if __name__=="__main__":
start=int(input())
end=int(input())
print(solve(start,end))

0 comments on commit e010314

Please sign in to comment.