FastPrepFastPrep
Problem Brief

Replacing Val πŸ“

INTERNOA

Sup πŸ‘‹!

This time the agency will give you:

  • An int 2D arr
  • A position within the input 2D arr
  • A so called replacing val
  • What they want you to do:

    Replace the val at the starting position with the provided replacing val. Repeat this process for all positions connected to the starting position via sides with the same val as the starting position.

    1Example 1

    Input
    replacingVal = 2, arr = [[0, 1, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 0, 0, 0], [0, 1, 0, 1, 0]], pos = [1, 2]
    Output
    [[0, 2, 0, 0, 0], [2, 2, 2, 0, 0], [2, 2, 0, 0, 0], [0, 2, 0, 1, 0]]
    Explanation
    No explanation is provided for now. For original prompt, pls refer source image.

    Constraints

    Limits and guarantees your solution can rely on.

  • Unknown for now 🀲
  •   public int[][] replacingNum(int replacingVal, int[][] arr, int[] pos) {
          // write your code here (lc733 might help)
      }
      
    Input

    replacingVal

    2

    arr

    [[0, 1, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 0, 0, 0], [0, 1, 0, 1, 0]]

    pos

    [1, 2]

    Output

    [[0, 2, 0, 0, 0], [2, 2, 2, 0, 0], [2, 2, 0, 0, 0], [0, 2, 0, 1, 0]]

    Sign in to submit your solution.