DatabricksOA #2
Bouncing Diagonal Sort
估计中等评测数据准备中,可先阅读题面
考点(AI 标注)模拟/实现原地数组
You're given a square matrix matrix of size n × n. Define a bouncing diagonal starting from the left column as the sequence of elements obtained by starting at some cell (i, 0), moving diagonally up-right until hitting the top row, then bouncing diagonally down-right, and so on (alternating direction whenever you hit top or bottom).
Define the weight of a leftmost-column element as the sum of all elements in its bouncing diagonal. Return the leftmost column reordered so that weights are in ascending order. In case of a tie, sort by value in ascending order.
Example: for matrix = [[1,2,3],[4,5,6],[7,8,9]], row 0's diagonal is 1+5+9=15 (down-right), row 1's bounces 4+8+6=18, row 2's bounces 7+5+3=15. Weights (15,15,18) after tie-break by value give new first column [1, 7, 4].