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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Utopian Tree
  5. Discussions

Utopian Tree

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

    You are viewing a single comment's thread. Return to all comments →

  • veenaonkar790
    3 months ago+ 0 comments

    Python Solution

    def utopianTree(n):
        out = []
        for i in range(n+1):
            if i==0:
                out.append(1)
            elif i%2==0 and i!=0:
                out.append(out[-1]+1)
            else:
                out.append(out[-1]*2)
        
        return out[n]
                
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy