• + 0 comments

    Here is a nice c# recurcive solution...

    public static int utopianTree(int n)
        {
            if(n == 0){
                return 1;
            }
            if(n==1){
                return 2;
            }
            if(n>1){
                if(n % 2 == 0){
                    return utopianTree(n-1) + 1;
                }else{
                    return utopianTree(n-1)*2;
                }
            }else{
                return 0;
            }
        }