Matrix Cells in Distance Order || JAVASCRIPT || Solution by Bharadwaj
Approach\nHashing\n\n# Complexity\n- Time complexity:\nTime: O(r*c)\n\n- Space complexity:\nO(r+c)\n\n# Code\n\nvar allCellsDistOrder = function(r, c, r0, c0) {
# Approach\nHashing\n\n# Complexity\n- Time complexity:\nTime: O(r*c)\n\n- Space complexity:\nO(r+c)\n\n# Code\n```\nvar allCellsDistOrder = function(r, c, r0, c0) {\n    let buckets = [];\n    let ret = [];\n    for(let i = 0; i < r; ++i){\n        for(let j = 0; j < c; ++j){\n            let dis = Math.abs(i - r0) + Math.abs(j - c0);\n            if(buckets[dis] === undefined) buckets[dis] = [];\n            buckets[dis].push([i, j]);\n        }\n    }\n    for(let bucket of buckets){\n       ret.push(...bucket);\n    }\n    return ret;\n};\n```
['JavaScript']