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

13

Avg. time to solve

12 min

Success Rate

80%

Problem Statement

```
For given 2D array :
[ [ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ] ]
After 90 degree rotation in anti clockwise direction, it will become:
[ [ 3, 6, 9 ],
[ 2, 5, 8 ],
[ 1, 4, 7 ] ]
```

```
The first line of input contains an integer 'T' representing the number of the test case. Then the test case follows.
The first line of each test case contains an integer 'N' representing the size of the square matrix ARR.
Each of the next 'N' lines contains 'N' space-separated integers representing the elements of the matrix 'ARR'.
```

```
For each test case, return the rotated matrix.
```

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

```
1 ≤ T ≤ 50
1 ≤ N ≤ 100
1 ≤ ARR[i][j] ≤ 10^9
Time Limit: 1 sec
```

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

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

```
(i) The array has been rotated by 90 degrees in an anticlockwise direction as the first row is now the first column inverted and so on for second and third rows.
(ii) The array has been rotated by 90 degrees in an anticlockwise direction as the first row is now first column inverted and so on for second, third and fourth rows.
```

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

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

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