Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Points From Grid Queries

med
30 min
Try to solve the Maximum Number of Points From Grid Queries problem.

Statement

You are given an integer matrix grid of size m by n and an integer array queries of size k.

For each query queries[i], you start at the top left cell (0,0)(0, 0) and earn points based on the following rules:
If the value at grid[0][0][0][0] is greater than or equal to queries[i], you cannot visit any cells and earn 00 points.
Otherwise, you start at cell (0,0)(0, 0) and can repeatedly move to any adjacent cell (up, down, left, or right) that has not been visited yet, as long as the value in that adjacent cell is strictly less than queries[i].
Each uniquely visited cell adds 11 point to your total score.

Return an array answer of size k where answer[i] is the maximum number of points you can earn for the query queries[i].

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 2≤2 \leq m, n ≤1000\leq 1000

  • 4≤4 \leq m * n ≤105\leq 10^5

  • k == queries.length

  • 1≤1 \leq k ≤104\leq 10^4

  • 1≤1 \leq grid[i][j], queries[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Points From Grid Queries

med
30 min
Try to solve the Maximum Number of Points From Grid Queries problem.

Statement

You are given an integer matrix grid of size m by n and an integer array queries of size k.

For each query queries[i], you start at the top left cell (0,0)(0, 0) and earn points based on the following rules:
If the value at grid[0][0][0][0] is greater than or equal to queries[i], you cannot visit any cells and earn 00 points.
Otherwise, you start at cell (0,0)(0, 0) and can repeatedly move to any adjacent cell (up, down, left, or right) that has not been visited yet, as long as the value in that adjacent cell is strictly less than queries[i].
Each uniquely visited cell adds 11 point to your total score.

Return an array answer of size k where answer[i] is the maximum number of points you can earn for the query queries[i].

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 2≤2 \leq m, n ≤1000\leq 1000

  • 4≤4 \leq m * n ≤105\leq 10^5

  • k == queries.length

  • 1≤1 \leq k ≤104\leq 10^4

  • 1≤1 \leq grid[i][j], queries[i] ≤106\leq 10^6