Zepruv › Coding problems

Diagonal Traverse

Medium · Array, Matrix, Simulation

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]

Constraints

Starter code (python)

class Solution(object):
    def findDiagonalOrder(self, mat):
        """
        :type mat: List[List[int]]
        :rtype: List[int]
        """
        

Related problems

Previous: Next Greater Element I · Next: Next Greater Element II · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.