← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given an integer matrix grid and an array queries. Starting from the top-left cell, you may move in four directions (up, down, left, or right) from a cell if it is within the grid. 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.
Example 1:
Input: grid = [[1,2],[3,4]], queries = [1] Output: [1] Explanation: From the top-left cell, we can reach 1 cell with value 1.
Example 2: ` Input: grid = [[5,7,5],[7,11,3],[5,3,9]], queries = [11,9,5] Output: [2,2,6] Explanation:
1 <= grid.length <= 1051 <= grid[0].length <= 1051 <= grid[i][j] <= 1051 <= queries.length <= 1050 <= queries[i] < 105