This is a verified interview question from Texas. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Alternate Row-Column Sorting of a Square Matrix - Texas Online Assessment NIT Bhopal PYQ" covers key patterns like Arrays.
"You are given a square matrix of size **M × M**. Perform the following operations on the matrix: ### Step 1 (Row-wise Sorting) Sort every row as follows: * 1st row in **ascending** order (left to right). * 2nd row in **descending** order. * Continue alternating for all rows. ### Step 2 (Column-wise Sorting) Using the matrix obtained after Step 1, sort every column as follows: * 1st column in **ascending** order (top to bottom). * 2nd column in **descending** order. * Continue alternating for all columns. Print the final matrix after both operations. --- ## Input Format * First line contains an integer **M**, the size of the square matrix. * Next **M** lines each contain **M** space-separated integers. --- ## Output Format Print the transformed **M × M** matrix. Each row should be printed on a new line with space-separated integers. --- ## Constraints * (1 <= M < 100) * The matrix is always square. --- ## Sample Input 1 ```text 3 3 2 1 4 5 6 9 8 7 ``` ## Sample Output 1 ```text 7 2 9 6 5 4 1 8 3 ``` --- ## Explanation Original matrix ```text 3 2 1 4 5 6 9 8 7 ``` After row sorting ```text 1 2 3 6 5 4 7 8 9 ``` After column sorting ```text 7 2 9 6 5 4 1 8 3 ``` --- ## Sample Input 2 ```text 2 4 6 9 8 ``` ## Sample Output 2 ```text 9 6 4 8 ```"
Join thousands of developers practicing for Texas.