2503. Maximum Number of Points From Grid Queries #27
Unanswered
IamShiwangi
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
2503. Maximum Number of Points From Grid Queries
Problem Statement
You are given an
m x n
integer matrixgrid
and an arrayqueries
of sizek
.Find an array
answer
of sizek
such that for each integerqueries[i]
, you start in the top-left cell of the matrix and repeat the following process:queries[i]
is strictly greater than the value of the current cell, then:After processing each query,
answer[i]
is the maximum number of points you can collect.Return the resulting array
answer
.Example 1
Input:
Output:
Explanation:
For each query:
5
cells.8
cells.1
cell.Example 2
Input:
Output:
Explanation:
Constraints
m == grid.length
n == grid[i].length
2 <= m, n <= 1000
4 <= m * n <= 10⁵
k == queries.length
1 <= k <= 10⁴
1 <= grid[i][j], queries[i] <= 10⁶
Discussion
Approach 1: Min-Heap + BFS (Optimized Approach)
answer
.Time Complexity:
Space Complexity:
🔥 Optimized Solution Using Python
🎯 How to Contribute
📂 File Structure
🔥 Want to Participate?
🔗 Useful Links
💡 Let's learn, code, and grow together! 🚀
Beta Was this translation helpful? Give feedback.
All reactions