Watch 10 video solutions for Diagonal Traverse II, a medium level problem involving Array, Sorting, Heap (Priority Queue). This walkthrough by Algorithms Made Easy has 48,928 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.
Example 1:
Input: nums = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,4,2,7,5,3,8,6,9]
Example 2:
Input: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]] Output: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]
Constraints:
1 <= nums.length <= 1051 <= nums[i].length <= 1051 <= sum(nums[i].length) <= 1051 <= nums[i][j] <= 105