We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Solution 3: More readable version of the first solution Average(1.47 µs):
defutopianTree(n):is_even=n%2==0# adjust n so is divisible by 2adusted_n=nifis_evenelsen+1# truncate float value from division -> parse to inthalf_cycles=(adusted_n/2).__trunc__()+1growth_factor=2**half_cyclesifis_even:returngrowth_factor-1returngrowth_factor-2
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Utopian Tree
You are viewing a single comment's thread. Return to all comments →
Here's my solutions in python:
Tested when n =
1000
Solution 1: Average(961 ns)
Solution 2: Average(138 µs):
Solution 3: More readable version of the first solution Average(1.47 µs):