Problem · Graph

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

Learn this problem
MediumUber logoUberNEW GRADOA
See Uber hiring insights

Problem statement

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

    canAscend(wall: String[][]) → int

    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

    Examples

    Example 1

    wall = [["x","x",".","x"],[".","x",".","."],[".","x",".","x"], [".", "x", ".", "."]]return = 2
    🐡

    More Uber problems

    drafts saved locally
    public int canAscend(String[][] wall) {
      // write your code here
    }
    
    wall[["x","x",".","x"],[".","x",".","."],[".","x",".","x"], [".", "x", ".", "."]]
    expected2
    checking account