<p>Given a 2D integer array <code>nums</code>, return <em>all elements of </em><code>nums</code><em> in diagonal order as shown in the below images</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/08/sample_1_1784.png" style="width: 158px; height: 143px;" />
<pre>
<strong>Input:</strong> nums = [[1,2,3],[4,5,6],[7,8,9]]
<strong>Output:</strong> [1,4,2,7,5,3,8,6,9]
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/08/sample_2_1784.png" style="width: 230px; height: 177px;" />
<pre>
<strong>Input:</strong> nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]]
<strong>Output:</strong> [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i].length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= sum(nums[i].length) &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i][j] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution {
public:
    vector<int> findDiagonalOrder(vector<vector<int>>& nums) {
        map<int, priority_queue< pair<int,int> , vector<pair<int,int>> > > m1;
        for(int i=0;i<nums.size();i++){
            for(int j=0;j<nums[i].size();j++){
                int sum = i+j;
                m1[sum].push({i,nums[i][j]});;
            }
        }
        vector<int> ans;
        for(auto i:m1){
            while( i.second.empty() == false ){
                ans.push_back(i.second.top().second);
                i.second.pop();
            }
        }
        return ans;
        // int maxcolsize=-1;
        
        // for(int i=0;i<nums.size();i++){
        //     int a=i,b=0;
        //     maxcolsize = max(maxcolsize, (int)(nums[i].size()) );

        //     while(a>=0){
        //         if(b < nums[a].size() )
        //             ans.push_back(nums[a][b]);
        //         b++;
        //         a--;
        //     }
        // }
        // for(int i=1;i<maxcolsize;i++){
        //     int a=i,b=nums.size()-1;
        //     // nums[b][a]

        //     while(a<maxcolsize && b>=0){
        //         if(a < nums[b].size() )
        //             ans.push_back(nums[b][a]);
        //         b--;
        //         a++;
        //     }
        // }
        // return ans;
        
    }
};
117809