Let's have some fun with 2D Matrices! Write a method **clockwise spiral order** and append the elements to an output

`findSpiral`

to traverse a 2D matrix of `int`

s in a `ArrayList`

if `Integer`

s.Example:

Input Matrix :

{1, 2, 3}

{4, 5, 6}

{7, 8, 9}

Output ArrayList:[1, 2, 3, 6, 9, 8, 7, 4, 5]

Need a **hand?** Try out these hints, one at a time.

Getting the dimensions of the 2D Array is important. Whenever you're solving problems involving 2D Arrays, start with

`int m = arr.length, n = arr[0].length;`

Use 4

Enclose the loops within an outer while loop :

`for`

loops to traverse the 2D Array.Enclose the loops within an outer while loop :

`while(m>0 && n>0)...`

and decrement `m`

and `n`

inside the loop.
public static ArrayList<Integer> findSpiral(int[][] arr) { }

**C**

**Java**

**Python**