Created
June 27, 2016 13:45
-
-
Save lsitters/bdae0b0685e89fc3ba13317db7c24582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @desc https://www.hackerrank.com/challenges/utopian-tree | |
* @param integer n | |
* @return integer of the height of the Utopian Tree after n cycles | |
*/ | |
function utree (n) { | |
if(n===0){ | |
return 1; | |
} | |
// a(n) = a(n-1) (+ 1 || * 2) | |
var tail = utree(n-1); | |
if(n%2){ | |
return 2*tail; | |
}else{ | |
return 1+tail; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment