• + 3 comments

    O(N) Solution: Reverse the original array Make an array sum which stores sum until ith element Make a 1D dp array. For each game the maximum sum a player can get is Sum[i] - (the sum other player can get in the remaining bricks) i.e. maximum of (sum[i] - dp[i-1] (selecting only one brick), sum[i]- dp[i-2] (2 bricks), sum[i] - dp[i-3] (3 bricks)) Take care of base cases