Back to problems

Maximum Number of Points from Grid Queries

Algorithm · Uber · Hard

You receive an integer matrix named grid (int[][]) along with an integer array called queries (int[]). Begin at the upper-left position and travel one step at a time in any of the four cardinal directions. For every threshold q, determine the number of cells reachable from that starting position when every visited cell must contain a value smaller than q. Produce these counts in the same sequence as the input queries. Examples Example 1: Input: grid =…

Checking your access…