Company: Texas Instruments
Difficulty: easy
You are given a square matrix of size `M × M`. Apply the following operations in order, then output the final matrix. - `Step 1 - Row pass:` Traverse the rows from top to bottom. Sort the `1st` row in ascending order, the `2nd` row in descending order, and continue alternating ascending and descending for all `M` rows (`3rd` ascending, `4th` descending, and so on). - `Step 2 - Column pass:` After `Step 1` has been applied to every row, traverse the columns and sort each column in ascending order from top to bottom. Every column is sorted ascending in this step. - `Step 3 - Output:` Print the matrix obtained after completing `Step 1` and `Step 2`. **Example 1:** **Input:** ``` 3 1 2 3 4 5 6 7 8 9 ``` **Output:** ``` 1 2 3 6 5 4 7 8 9 ``` **Explanation:** - Original matrix: ``` 1 2 3 4 5 6 7 8 9 ``` - After `Step 1` (`row 1` ascending, `row 2` descending, `row 3` ascending): ``` 1 2 3 6 5 4 7 8 9 ``` - After `Step 2` (every column sorted ascending - `column 1` is `[1, 6, 7]`, `column 2`