Skip to content

Instantly share code, notes, and snippets.

@lsitters
Created June 27, 2016 13:45
Show Gist options
  • Save lsitters/bdae0b0685e89fc3ba13317db7c24582 to your computer and use it in GitHub Desktop.
Save lsitters/bdae0b0685e89fc3ba13317db7c24582 to your computer and use it in GitHub Desktop.
/*
* @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