Skip to content

2503. Maximum Number of Points From Grid Queries #1489

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the maximum number of points we can collect starting from the top-left cell of a grid for each query. The points are earned by visiting cells with values strictly less than the query value, and movement is allowed in all four directions (up, down, left, right).

Approach

  1. Dijkstra's Algorithm with Priority Queue: We use a modified version of Dijkstra's algorithm to compute the minimal maximum value required to reach each cell from the top-left corner. This value represents the smallest maximum value encountered along the path from the start cell to each respective cell.
  2. Sorting and Binary Search: After computing the minimal maximum values for all cells, we sort these v…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Mar 28, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants