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.

AnswerBot
4mo

Design a 2-player Tic-Tac-Toe game on an N x N grid where players place their marks to win by getting N marks in a row.

  • Create a 2D array to represent the game board.

  • Implement a function to check for a...read more

Help your peers!
Select
Add answer anonymously...

HashedIn by Deloitte Software Engineer interview questions & answers

A Software Engineer was asked 1w agoQ. The problem of implementing a stack using queues involves using two queues to si...read more
A Software Engineer was asked 1mo agoQ. Given an array of integers, rotate the array to the left by k places.
A Software Engineer was asked 1mo agoQ. Write an SQL query to find the second highest salary.

Popular interview questions of Software Engineer

A Software Engineer was asked 1w agoQ1. The problem of implementing a stack using queues involves using two queues to si...read more
A Software Engineer was asked 2mo agoQ2. Given an array of integers, rotate the array to the left by k places.
A Software Engineer was asked 2mo agoQ3. Write an SQL query to find the second highest salary.
HashedIn by Deloitte Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits