Airbnb Phone Screen : Connect Four

airbnb logo
airbnb
October 21, 202510 reads

Summary

I had a phone screen with Airbnb where I was tasked with implementing the Connect Four game logic, focusing on well-structured code and handling game states like full columns and winning conditions.

Full Experience

During my phone screen at Airbnb, I was presented with the challenge of implementing the classic game Connect Four. The interviewer provided a clear problem statement, outlining the game rules, input format, and expected output for displaying the grid and handling various game states. The emphasis was on writing well-structured code rather than focusing purely on immediate optimizations, with the possibility of discussing further optimizations as follow-up.

Interview Questions (1)

Q1
Connect Four Game Implementation
Data Structures & AlgorithmsMedium

Connect Four is a two-player connection board game. The players choose a color and then take turns dropping colored tokens into a seven-column, six-row vertically suspended grid. The pieces fall straight down, occupying the lowest available space within the column. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of four of one's own tokens. - Wikipedia

The input is a list of columns played successively by the two players. The output is to display the Connect Four grid associated when the game finishes.

If a winning state is reached or if a wrong move is played, the game should stop even if there are still columns in the list. In that case, only the tokens that have been played should be displayed in the grid.

The goal is to write code that is well-structured, rather than a solution that is too complex. Optimisation may be discussed during follow-up questions.

Examples:

Input (column full):

[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]

Output:

| | |X| | | | |
| | |0| | | | |
| | |X| | | | |
| | |0| | | | |
| | |X| | | | |
| | |0| | | | |

In this example, we start playing with the 0 token. The 7th item of the input is invalid because the column is already full.

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!