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.
- Prepare
- Algorithms
- Implementation
- Utopian Tree
- Discussions
Utopian Tree
Utopian Tree
Sort by
recency
|
2001 Discussions
|
Please Login in order to post a comment
// the function code will be simply............. public static int utopianTree(int n) { int height=1; for(int i=0;i
}
solution 1: O(1) cpp solution--
int utopianTree(int n) { int exponent=n/2 +1 +n%2; int result=pow(2,exponent); if(n%2==0){ return result-1; } else{ return result-2; } }
Here is my c++ solution, you can watch the explanation here : https://youtu.be/0G-kEeQC25E
Solution 1 : O(N)
Solutoin 2 : O(1)
Solutoin 3 : O(1)
Solutoin 4 : O(1)
Php solution;