Apple | Phone Screen | SWE
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-10-01Added By Anonymous
Source: Link
1shown in the figure below, there are several pieces of X and Y stones on the 4x4 board; O represents an empty space.
2
3# We can choose any stone at any step, and move it to an empty space. (top, bottom, left, and right).
4
5# We want to know the minimum number of steps to achieve a winning situation: 4 Xs or 4 Ys are connected in a row.
6
7## Initially
8
9# OXXY
10# YOOX
11# XOOY
12# XOXX
13
14# Input: 4x4 board
15# Output: Minimum number of moves the stones to achieve a winning situation. IF not possible winning state, return -1