Tic-Tac-Toe Design Problem
Design a 2-player Tic-Tac-Toe game played on an N
* N
grid where Player 1 uses ‘X’ and Player 2 uses ‘O’. A move is always valid and occupies an empty spot.
If a player places N
of their marks consecutively in a row (horizontal, vertical, or diagonal), they win the game. No further moves are allowed after a win.
Input:
1. An integer ‘T’ representing the number of test cases.
2. For each test case:
a. An integer ‘N’ for the grid size (N x N).
b. An integer ‘Q’ denoting the number of queries.
c. ‘Q’ lines of three space-separated integers ‘ROW’, ‘COL’, and ‘PLAYER’ indicating the move position and player.
Output:
For each move, return:
0: if no player wins.
1: if Player 1 wins.
2: if Player 2 wins.
The result should be printed for each test move in a new line.
Example:
If ‘N’ = 3:
Player 1 places ‘X’, Player 2 places ‘O’ on an empty board.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 100
5 ≤ Q ≤ N * N
0 ≤ ROW, COL < N
PLAYER ∈ {1, 2}
Note:
Implement the function move(row, col, player)
and return the result for each move. No printing required as it is handled externally.
Be the first one to answer
Add answer anonymously...
Top HashedIn by Deloitte Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in HashedIn by Deloitte Software Engineer
>
HashedIn by Deloitte Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app