Menu

1 / 3

3225. Maximum Score From Grid Operations

DEV Community·MD ARIFUL HAQUE·6 months ago
#CoooaUu7
#leetcode#php#algorithms#programming#column
Reading 0:00
15s threshold

3225. Maximum Score From Grid Operations

Difficulty: Hard

Topics: Principal , Array , Dynamic Programming , Matrix , Prefix Sum , Biweekly Contest 135

You are given a 2D matrix grid of size n x n . Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices (i, j) , and color black all the cells of the jᵗʰ column starting from the top row down to the iᵗʰ row.

The grid score is the sum of all grid[i][j] such that cell (i, j) is white, and it has a horizontally adjacent black cell.

Return the maximum score that can be achieved after some number of operations .

Example 1:

Input: grid = [[0,0,0,0,0],[0,0,3,0,0],[0,1,0,0,0],[5,0,0,3,0],[0,0,0,0,2]]

Output: 11

Explanation: In the first operation, we color all cells in column 1 down to row 3, and in the second operation, we color all cells in column 4 down to the last row.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.