2503. Maximum Number of Points From Grid Queries Hard
1/**
2 * [2503] Maximum Number of Points From Grid Queries
3 *
4 * You are given an m x n integer matrix grid and an array queries of size k.
5 * Find an array answer of size k such that for each integer queres[i] you start in the top left cell of the matrix and repeat the following process:
6 *
7 * If queries[i] is strictly greater than the value of the current cell that you are in, then you get one point if it is your first time visiting this cell, and you can move to any adjacent cell in all 4 directions: up, down, left, and right.
8 * Otherwise, you do not get any points, and you end this process.
9 *
10 * After the process, answer[i] is the maximum number of points you can get. Note that for each query you are allowed to visit the same cell multiple times.
11 * Return the resulting array answer.
12 *
13 * <strong class="example">Example 1:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2022/10/19/yetgriddrawio.png" style="width: 571px; height: 151px;" />
15 * Input: grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]
16 * Output: [5,8,1]
17 * Explanation: The diagrams above show which cells we visit to get points for each query.
18 * <strong class="example">Example 2:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2022/10/20/yetgriddrawio-2.png" />
20 * Input: grid = [[5,2,1],[1,1,2]], queries = [3]
21 * Output: [0]
22 * Explanation: We can not get any points because the value of the top left cell is already greater than or equal to 3.
23 *
24 *
25 * Constraints:
26 *
27 * m == grid.length
28 * n == grid[i].length
29 * 2 <= m, n <= 1000
30 * 4 <= m * n <= 10^5
31 * k == queries.length
32 * 1 <= k <= 10^4
33 * 1 <= grid[i][j], queries[i] <= 10^6
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximum-number-of-points-from-grid-queries/
39// discuss: https://leetcode.com/problems/maximum-number-of-points-from-grid-queries/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn max_points(grid: Vec<Vec<i32>>, queries: Vec<i32>) -> Vec<i32> {
45 vec![]
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2503() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.