All practice tasks

Coding (Algo)

Count Clear Routes

Dynamic programming · Medium

A grid planner counts routes through a rectangular layout with blocked cells. A route always moves one cell right or down, so it never revisits a cell. The caller needs the exact count for a layout whose total fits in a safe integer.

Return the number of clear right-and-down routes from the top-left cell to the bottom-right cell.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

A JSON object { "grid": number[][] } containing only 0 and 1.

Fields

  • grid is rectangular and contains only 0 (clear) and 1 (blocked).

Output

Return value

  • Return an integer count. An empty grid or a grid with zero columns returns 0.
  • A blocked start or destination returns 0. A single clear cell has one route: no moves.
  • Only right and down moves are allowed.

Constraints

  • 0 <= rows, columns <= 500.
  • Every count reaching any cell is at most Number.MAX_SAFE_INTEGER. This explicit input promise avoids silently rounded JSON results.

Examples

Example 1

{
  "grid": [
    [
      0,
      0,
      0
    ],
    [
      0,
      1,
      0
    ],
    [
      0,
      0,
      0
    ]
  ]
}

Returns

2

The center blocks the other routes.

Example 2

{
  "grid": [
    [
      0
    ]
  ]
}

Returns

1

The empty move sequence is valid.

Required complexity

O(rows * columns) time and O(columns) extra space

What this task practices

Count Clear Routes is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.