NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

(This question is a variation of the LeetCode question 1914. Cyclically Rotating a Grid. If you haven't completed that question yet, it is recommended to solve it first.)

An integer matrix can be divided into concentric layers. You are given a rectangular matrix matrix with n rows and m columns. The outer border is layer 0, and each successive inner border is the next layer, as illustrated below.

Test Cases
Input
Output
Expected