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.
defutopianTree(n):# Set the initial height of the treeheight=1# Let's setup a range that'll cover every cycle and iterate through it.forcycleinrange(0,n+1):# Nothing happens during the first cycle, so we skip the rest of the loop.ifcycle==0:continue# Odd cycles are 'spring', so we add height to itself, otherwise add 1.height+=heightifcycle%2==1else1returnheight
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 →
A solution in Python, with some comments.