Level: Mid-Level
Round: Onsite · Type: Coding · Difficulty: 8/10 · Duration: 60 min · Interviewer: Neutral
Topics: Game Simulation, String Manipulation
Location: San Francisco Bay Area
Interview date: 2025-03-05
Got offer: False
I had an onsite interview focused on a coding question.
The interview involved simulating a game. The rules were long and complex, reminiscent of HackerRank problems. I needed to read the instructions multiple times to understand them, and I reviewed two examples with the interviewer to clarify the requirements.
The game involves two players on a square board. The input consists of a string array of moves and the board size, and the output is a string indicating the game result. Moves can be either 'place' or 'toggle'. 'Place' puts a piece on the current cell, while 'toggle' moves the piece in a specified direction. When toggling, the player moves the piece one cell at a time, capturing any opponent's pieces. Pieces moving beyond the board are discarded. The first character of each move string indicates the action ('p' for place, 't' for toggle). The second and third characters represent the coordinates (row, col). For toggle moves, the fourth character specifies the direction ('u', 'd', 'l', 'r' for up, down, left, right). 'Place' actions switch players, while 'toggle' actions do not. After all moves, the game result is determined by which player has pieces remaining on the board. I had to return "player1 is the winner", "player2 is the winner", or "in progress" accordingly.
During the interview, there was a potential error in one of the provided examples, and I didn't have a chance to fully review the rules, possibly missing details about the 'place' action and whether players can place pieces in the same cell. I asked the interviewer, and they confirmed that players could place pieces in the same cell, but I didn't double-check the rules myself. I'm unsure if there were any capture mechanics during the placement.
I barely finished the coding, and I had less than five minutes for debugging. I encountered compilation errors during the two attempts to run the code, and I didn't have time to fix them. After the interview, I rewrote the code in LeetCode playground and was able to get it running. The code was fairly extensive.