FastPrepFastPrep
Problem Brief

Ascend Vertical Wall (For off-campus 2025 batch hiring :)

NEW GRADOA

Heads up~~ The OP mentioned that the description of this question might not be very accurate or polished as they could barely recall the question now.

A robot whose battery capacity is w, wants to ascend a vertical 2D wall (N x M). It can start from any cell in the bottom row and wants to reach any cell in the top row. Each cell can be 'x', meaning the robot can hop on that cell or a '.', meaning the robot can't hop on that node. However, there are some conditions it has to follow:

  • It can only move in horizontal (along the same row) or up direction.
  • The robot currently at (x₁, y₁) can only jump to (x₂, y₂), if the Euclidean distance between these two cells is less than or equal to w (robot battery capacity).
  • Due to some sensor constraints, it can hop at most 2 nodes horizontally (along the same row).
  • The first line of input is the number of rows, number of columns, and the battery capacity. The second line is a 2D wall cell graph.

    Function Description

    Complete the function canAscend in the editor.

    canAscend has the following parameter:

    1. String[][] wall: a 2D array representing the wall cells

    Returns

    int: the minimum number of hops required to ascend the wall, or -1 if it's not possible

    1Example 1

    Input
    wall = [["x","x",".","x"],[".","x",".","."],[".","x",".","x"], [".", "x", ".", "."]]
    Output
    2
    Explanation
    🐡
    public int canAscend(String[][] wall) {
      // write your code here
    }
    
    Input

    wall

    [["x","x",".","x"],[".","x",".","."],[".","x",".","x"], [".", "x", ".", "."]]

    Output

    2

    Sign in to submit your solution.