Login

Top Apple Coding Interview Questions

Problem title

Difficulty

Avg time to solve

Maximum Size Rectangle Sub-matrix With All 1's

Hard

10 mins

Minimum Number Of Taps To Water Garden

Hard

15 mins

Morse Code To English

Easy

15 mins

Print Nodes at Distance K From a Given Node

Hard

20 mins

Spiral Matrix

Easy

15 mins

Inplace rotate matrix 90 degree

Easy

12 mins

House Robber

Moderate

15 mins

Merge Two Sorted Linked Lists

Moderate

15 mins

Palindrome Partitioning

Hard

25 mins

Right View

Moderate

35 mins

Problem

Submissions

11

Avg. time to solve

15 min

Success Rate

80%

Problem Statement

```
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains two single space-separated integers 'N' and 'M', denoting the number of rows and columns respectively.
The next 'N' lines, each contains 'M' single space-separated integers representing the elements in a row of the matrix.
```

```
For each test case/query, print the spiral path of the given matrix.
The output for every test case will be printed in a separate line.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 5
1 <= N <= 10 ^ 2
1 <= M <= 10 ^ 2
-10 ^ 9 <= MATRIX[ i ][ j ] <= 10 ^ 9
Time Limit: 1sec.
```

```
2
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3 6
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
```

```
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11
```

```
The spiral path for the test case 2 is as shown below:
```

```
2
1 1
4
1 5
1 2 3 4 5
```

```
4
1 2 3 4 5
```

```
In the first test case, there is only one element in the matrix, so the spiral path is only that element.
In the second test case, there is only one row or 1-D matrix, so the spiral path is only the single traversal of the matrix.
```

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