Sort by

recency

|

107 Discussions

|

  • + 0 comments

    arr); n + 1, 0);

    // Base cases
    $dp[0] = 0; // If no bricks, score is 0
    `$dp[1] = $`arr[0]; // If only one brick, score is the value of that brick
    
    // Loop to calculate maximum score
    for (`$i = 2; $`i <= `$n; $`i++) {
        // At each step, we have three options: take 1, 2, or 3 bricks
        // We choose the option that minimizes the opponent's score
        `$dp[$`i] = max(
            `$arr[$`i - 1] + `$arr[$`i - 2] + (`$i >= 4 ? $`dp[$i - 3] : 0), // Take 3 bricks
            `$arr[$`i - 1] + (`$i >= 3 ? $`arr[`$i - 2] + $`dp[$i - 2] : 0), // Take 2 bricks
            `$arr[$`i - 1] + `$dp[$`i - 1] // Take 1 brick
        );
    }
    
    return `$dp[$`n]; // Return the maximum score
    
  • + 0 comments

    Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Bricks Game Problem Solution

  • + 0 comments

    Here is Bricks Game problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-bricks-game-problem-solution.html

  • + 0 comments

    For anyone stuck, here's a 2 line function that shows logic of the final solution:

    def makeMove(arr):
        if len(arr) <= 3: return sum(arr)
        return sum(arr) - min([makeMove(arr[i : len(arr)]) for i in range(1, 4)])
    

    It gives correct answer, but is not optimal. In order to solve it properly, it needs to be implemented using iteration instead of recursion

  • + 0 comments

    Did you know that there are actually three game modes that you can play in Bricks n Balls? Yes, there are, and you can select them from the main menu where the missions are displayed. Sometimes games like these are similar to strategy games at https://wildcardcityvip.com/. But it wasn't clear to me how you embed strategies through the code.