Skip to content

Practice Maximum Number of Points From Grid Queries

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2503
LeetCode Problem

Maximum Number of Points From Grid Queries

Problem Statement

For each query threshold, start at grid[0][0] and move through side-adjacent cells only while their values are strictly below the threshold. Each distinct visited cell earns one point; revisits are permitted without extra points. Return the greatest achievable points independently for each query, or 0 if the starting cell fails the threshold.

Source: Maximum Number of Points From Grid Queries on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]
Output
[5,8,1]

# Example 2

Input
grid = [[5,2,1],[1,1,2]], queries = [3]
Output
[0]

Constraints

m == grid.length
n == grid[i].length
2 <= m, n <= 1000
4 <= m * n <= 10^5
k == queries.length
1 <= k <= 10^4
1 <= grid[i][j], queries[i] <= 10^6

Related LeetCode Problems

Practice more problems similar to Maximum Number of Points From Grid Queries.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.