(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.
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected