Apple | Phone Screen | SWE

180
Oct 01, 2024
As shown in the figure below, there are several pieces of X and Y stones on the 4x4 board; O represents an empty space.

# We can choose any stone at any step, and move it to an empty space. (top, bottom, left, and right).

# We want to know the minimum number of steps to achieve a winning situation: 4 Xs or 4 Ys are connected in a row.

## Initially

# OXXY
# YOOX
# XOOY
# XOXX

# Input: 4x4 board
# Output: Minimum number of moves the stones to achieve a winning situation. IF not possible winning state, return -1
Comments (0)