Infosys OA Question 2024 September | Matrix | on-campus

Infosys · Question · Posted Jun 2026

Question: Spiral Matrix Problem Statement Given an m x n matrix, return all elements of the matrix in spiral order. Constraints m == matrix.length n == matrix[i].length 1 <= m, n <= 10 -100 <= matrix[i][j] <= 100 Examples Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5] Explanation 1: We traverse the outermost ring clockwise: top row left→right [1,2,3], right column top→bottom [6,9], bottom row right→left [8,7], left column bottom→top [4]. Then the inner element [5]. Combined: [1,2,3,6,9,8,7,4,5]. Example 2: ...

The full answer & interview discussion are available to premium members.

Log in Create a free account