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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Game Theory
  4. Tower Breakers - The Final Battle
  5. Discussions

Tower Breakers - The Final Battle

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 18 Discussions, By:

recency

Please Login in order to post a comment

  • cafelatte
    4 months ago+ 0 comments

    And here's another solution. How it works is explained further down, see the entry of @kiwic.

    ''' How many stones (maximum) can you fit in for given cost? 
        -> nmax(cost)
        Obviously every pile has to give this same cost, that is 
         -> nmax(cost-1^2) + nmax(cost-2^2)+...
    '''
    
    from functools import cache
    from itertools import count
    
    @cache
    def nmax(cost):
        if cost < 4: return 1
        return sum(nmax(cost-pile**2) 
    		                      for pile in range(1,int(math.sqrt(cost))+1))
                
    def towerBreakers(n):
        for cost in count():
            if nmax(cost)>=n: return cost
    
    0|
    Permalink
  • thecodingsoluti2
    10 months ago+ 0 comments

    Here is Tower Breakers - The Final Battle problem solution in Python Java C++ and C programming - https://programs.programmingoneonone.com/2021/07/hackerrank-tower-breakers-the-final--battle-problem-solution.html

    0|
    Permalink
  • ariwaisberg
    2 years ago+ 0 comments

    This is not a hard algorithm, rather it's a horrible game, hard to understand & poorly explained by the platform.

    1|
    Permalink
  • alex_fotland
    3 years ago+ 0 comments

    Precalculating all values in range for the inverse of the function you're actually interested in feels like a weird solution until you realize said inverse grows exponentially . . . I think. Frankly I wasn't very rigorous in my argument to myself that it isn't superexponential.

    0|
    Permalink
  • apandey0826
    3 years ago+ 1 comment

    According to problem statement x>=2 and k>= 1 and k<=x ;

    so for example if n=4; coin =0 (initially) 4=>{2,2} since k >=1 left {2} and coin=1^2=1 now 2=>{1,1} i.e. x=2; now take both coin 2^2=4 so answer = 1+4=5 then why 6 in testcase ...

    1|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy