← 返回 uber 的题目列表Maximum Number of Points from Grid Queries
类型:qbank
Given an integer matrix and an array of query values, count for each query how many cells are reachable from the top-left moving in four directions through cells whose value is strictly less than the query.
Maximum Number of Points from Grid Queries
Given an integer matrix and an array of query values, count for each query how many cells are reachable from the top-left moving in four directions through cells whose value is strictly less than the query.
SWE
grid
heap
bfs
sorting
hard
Frequency
Single report
Last asked
2026-05-29
Stage
phone-screen
Maximum Number of Points from Grid Queries
You are given an integer matrix grid and an array queries. Starting from the top-left cell, you may move in four directions.
For each query value q, count how many cells can be reached using only cells whose value is strictly less than q. Return the answers in the original query order.
Examples
Example 1:
Input: grid = [[1,2,3],[2,5,7],[3,5,1]], queries = [5,6,2]
Output: [5,8,1]
Constraints
2 <= grid.length, grid[i].length <= 1000
1 <= queries.length <= 10^4
1 <= grid[i][j], queries[i] <= 10^6