At the Robotics Innovation Campus "UBERBOT", Unit IG-0R is a vertical wall-climbing robot that can scale surfaces using embedded magnetic contact points (nodes). The robot is deployed on a vertical metal wall designed as a rectangular grid with:
Each segment is either:
Valid Route Criteria
Level-by-Level Progression: The robot may only move upward or horizontally; it cannot move to a lower level. The robot must access at least one node per level to recharge its navigation sensors.
Node Usage per Level: The robot can use up to two nodes per level (due to sensor synchronization constraints). These nodes can be used in any order, but each node is visited at most once in a route.
Battery Constraint: IG-0R's battery capacity allows it to jump only between nodes whose Euclidean distance is less than or equal to w, unit range.
The distance between two nodes at positions (i1, j1) and (i2, j2) is computed as:
sqrt((i1 - i2)^2 + (j1 - j2)^2)
The robot cannot transition between nodes if the computed distance exceeds its battery limit w.
w >= sqrt((i1 - i2)^2 + (j1 - j2)^2)
Complete the function countRoutes in the editor.
countRoutes has the following parameters:
- 1.
char[][] grid: a 2D array of characters representing the grid - 2.
w: an integer representing the maximum Euclidean distance the robot can jump
Returns
int: the number of distinct valid routes, computed modulo 998244353
grid = [
['X', 'X', '#', 'X'],
['#', 'X', 'X', '#'],
['#', 'X', '#', 'X']
]
w = 1
return = 2- 2 <= n <= 2000
- 1 <= m <= 2000
- 1 <= w <= 2000
An integer containing the number of distinct valid routes, computed modulo 998244353
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
public int countRoutes(char[][] grid, int w) {
// write your code here
}