Login

Top Apple Coding Interview Questions

Problem title

Difficulty

Avg time to solve

Largest Tree Value

Moderate

25 mins

Sum of Distance

Hard

25 mins

Factor Combinations

Moderate

35 mins

Count the repetitions

Hard

25 mins

Longest Duplicate SubString

Moderate

30 mins

Construct Binary Tree From Inorder and Preorder Traversal

Easy

10 mins

Vertical Order Traversal

Moderate

35 mins

Serialize/Deserialize The Binary Tree

Hard

15 mins

Tic-Tac-Toe Winner

Easy

20 mins

Find the Good Matrix

Moderate

30 mins

Problem

Submissions

3

Avg. time to solve

20 min

Success Rate

80%

Problem Statement

```
n = 5, moves = {{0,2}, {0,0}, {1,1}, {2,2}, {2,0}}
```

```
1. The array ‘moves’ doesn’t contain any repeating positions, and all positions are valid.
2. The array ‘moves’ follows all the rules of tic-tac-toe.
3. You do not need to print anything; it has already been taken care of. Just implement the function
```

```
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains an integer ‘N’ denoting the size of the array ‘moves’.
The next ‘N’ lines of each test case contain two space-separated integers denoting a tuple of the array ‘moves’.
```

```
For each test case, if there is a winner, print their name, i.e., ‘player1’ or ‘player2’. Otherwise, depending on the grid’s final state, print ‘uncertain’ or ‘draw’ (without quotes).
```

```
1 <= T <= 1000
1 <= N <= 9
| moves[i] | = 2
0 <= moves[i][j] <= 2
Where ‘moves[i][j]’ represents elements in the array ‘moves’.
Time limit: 1 second
```

```
2
9
0 0
0 1
1 1
1 0
2 1
2 2
2 0
0 2
1 2
5
0 0
1 1
0 2
2 2
2 1
```

```
draw
uncertain
```

```
Test Case 1:
```

```
There is no row, column, or diagonal with three same characters after performing the given nine moves. Hence there is no winner. With no more moves to make (all grid positions are marked), the game ends in a draw. So, the answer is ‘draw’.
Test Case 2:
```

```
There is no row, column, or diagonal with three same characters after performing the given five moves. Hence there is no winner as of now. With four grid positions remaining unmarked, the winner of the game is uncertain. So, the answer is ‘uncertain’.
```

```
2
6
0 0
1 1
2 2
0 2
1 0
2 0
5
0 1
1 2
2 1
1 0
1 1
```

```
player2
player1
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code