[AtCoder] D - ABSRead more
[AtCoder] C - HSIRead more
[AtCoder] D - WallRead more
[Codeforces] Round #785 (Div. 2) C. Palindrome BasisRead more
[Codeforces] Round #787 (Div. 3) E. Replace With the Previous, MinimizeRead more
[Codeforces] Round #790 (Div. 4) H2. Maximum Crossings (Hard Version)Read more
[Codeforces] Round #797 (Div. 3) E. Price MaximizationRead more
[Codeforces] Round #810 (Div. 1) A. Color the PictureRead more
[LeetCode] Grid Game

2017. Grid Game

You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix.

Both robots initially start at (0, 0) and want to reach (1, n-1). Each robot may only move to the right ((r, c) to (r, c + 1)) or down ((r, c) to (r + 1, c)).

At the start of the game, the first robot moves from (0, 0) to (1, n-1), collecting all the points from the cells on its path. For all cells (r, c) traversed on the path, grid[r][c] is set to 0. Then, the second robot moves from (0, 0) to (1, n-1), collecting the points on its path. Note that their paths may intersect with one another.

The first robot wants to minimize the number of points collected by the second robot. In contrast, the second robot wants to maximize the number of points it collects. If both robots play optimally, return the number of points collected by the second robot.

Read more
[LeetCode] Remove Colored Pieces if Both Neighbors are the Same Color

2038. Remove Colored Pieces if Both Neighbors are the Same Color

There are n pieces arranged in a line, and each piece is colored either by ‘A’ or by ‘B’. You are given a string colors of length n where colors[i] is the color of the ith piece.

Alice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.

  • Alice is only allowed to remove a piece colored ‘A’ if both its neighbors are also colored ‘A’. She is not allowed to remove pieces that are colored ‘B’.
  • Bob is only allowed to remove a piece colored ‘B’ if both its neighbors are also colored ‘B’. He is not allowed to remove pieces that are colored ‘A’.
  • Alice and Bob cannot remove pieces from the edge of the line.
  • If a player cannot make a move on their turn, that player loses and the other player wins.

Assuming Alice and Bob play optimally, return true if Alice wins, or return false if Bob wins.

Read more