educative.io

Diagonal Traverse

What pattern does this problem fall into?
Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order.

Example 1:

Input: mat = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,4,7,5,3,6,8,9]

Example 2:
Input: mat = [[1,2],[3,4]]
Output: [1,2,3,4]

Hey @Ayaz_Pasha!
There is not any specific pattern for this problem in this course. But you can use the sliding window pattern after a few modifications.

thanks for the reply @Aiman_Fiaz
Could you pls share the solution for this problem using sliding window pattern?