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

7

Difficulty: MEDIUM

Avg. time to solve

30 min

Success Rate

65%

Problem Statement

```
Consider ARR = [[1 , 0 , 1] ,
[1 , 1 , 1] ,
[1 , 1 , 1]],
the Good matrix after updating the given matrix as described in the question is
[[0 , 0 , 0] ,
[1 , 0 , 1] ,
[1 , 0 , 1]].
Since ARR[0][1] is 0, we need to set all element’s values present in 0-th row and 1-th column to 0.
```

```
You do not need to print the matrix. Just change in the given input.
```

```
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains two integers, 'N' and ‘M’, denoting the number of rows and columns in the array.
The Next 'N' lines of each test case contain 'M' space-separated integers denoting the elements of the array 'ARR'.
```

```
For each test case, return the Good matrix after updating the given matrix as described in the question.
Print the output of each test case in a separate line
```

```
1 <= T <= 20
1 <= N <= 300
1 <= M <= 300
ARR[i][j] can only contain two values, i.e, 0 and 1.
Where 'T' denotes the number of test cases, 'N' and 'M' denotes the number of rows and the number of columns in the array ‘ARR’ respectively, and 'ARR[i][j]' denotes the ’j-th’ element of 'i-th' row of the array 'ARR'.
Time Limit: 1sec
```

```
2
2 2
0 1
1 1
3 3
1 1 0
1 1 1
1 1 1
```

```
0 0
0 1
0 0 0
1 1 0
1 1 0
```

```
For the first test case,
The Good matrix after updating the given matrix as described in the question is
[[0 , 0] ,
[0 , 1]].
Since ARR[0][0] is 0, we need to set all elements value present in 0-th row and 0-th column to 0.
For the second test case,
The Good matrix after updating the given matrix as described in the question is
[[0 , 0 , 0] ,
[1 , 1 , 0] ,
[1 , 1 , 0]].
Since ARR[0][2] is 0, we need to set all elements value present in 0-th row and 2-th column to 0.
```

```
2
4 4
1 1 1 1
0 1 1 1
1 1 1 1
0 1 1 1
3 3
0 1 1
0 1 1
1 1 1
```

```
0 1 1 1
0 0 0 0
0 1 1 1
0 0 0 0
0 0 0
0 0 0
0 1 1
```

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