2
pub fn diagonal_sort(mut mat: Vec<Vec<i32>>) -> Vec<Vec<i32>> {3
let mut buckets = [0; 101];4
let (m, n) = (mat.len(), mat[0].len());6
// Chain together iterators for first element coordinates of all relevant diagonals9
.chain((0..n - 1).map(|j| (0, j)))10
.for_each(|(i0, j0)| {11
let (mut i, mut j) = (i0, j0);12
let (mut min, mut max) = (i32::MAX, i32::MIN);13
// Populate buckets for bucket sorting14
while i < m && j < n {15
let element = mat[i][j];16
min = min.min(element);17
max = max.max(element);18
buckets[element as usize] += 1;22
// Populate matrix with result of bucket sorting23
let (mut i, mut j) = (i0, j0);24
let mut k = min as usize;25
while i < m && j < n {26
while buckets[k] == 0 {