Back to problems

Sort Every Concentric Matrix Border Clockwise

Algorithm · ByteDance · Hard

You are given a rectangular integer matrix matrix. For each valid concentric border k, collect that border's values in clockwise order starting at the border's top-left cell, sort those values in ascending order, and write the sorted values back into the same border cells in the same clockwise order. Return the transformed matrix as a new copy; do not mutate matrix. A border with index k has top row $$k$$, bottom row $$r - 1 - k$$, left column $$k$$, and right column $$c - 1…

Checking your access…