Tower Breakers

Sort by

recency

|

52 Discussions

|

  • + 0 comments

    Python best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    def tower_breakers(n, m):
        # Time complexity: O(1)
        # Space complexity (ignoring input): O(1)
        # If number of towers is pair, whatever player 1 does, player 2 mimics and wins.
        # If n is odd, player 1 push a tower to 1 and the game becomes a n is pair case
        if m == 1:
            return 2
        
        if n % 2 == 0:
            return 2
        else:
            return 1
    
  • + 0 comments

    Rust best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    fn tower_breakes(n: i32, m: i32) -> i32 {
        //Time complexity: O(1)
        //Space complexity (ignoring input): O(1)
        //If number of towers is pair, whatever player 1 does, player 2 mimics and wins.
        //If n is odd, player 1 push a tower to 1 and the game becomes a n is pair case
        if m == 1 {
            return 2;
        }
    
        if n % 2 == 0 {
            2
        } else {
             1
        }
    }
    
  • + 1 comment

    How come 5 is evently divises 6 in the example @@!

    • + 1 comment

      I'm stuck in the same problem as well, and check several times..... a waste of my time

      • + 0 comments

        I dopt another habit after this. If problem doens't make sense to me, I go to the discussion. lol

  • + 0 comments

    My Python Solution:

    return 2 if m==1 or n % 2 ==0 else 1

  • + 0 comments

    My rust solution:

    fn towerBreakers(n: i32, m: i32) -> i32 {
        if m == 1 || n % 2 == 0 { 
            2 
        } else { 
            1 
        }
    }