Skip to main content
All Questions

Rotate an n by n matrix clockwise by 90 degrees between one and four times while keeping the entries on both diagonals fixed.

Unlock detailed company stats for this questionUpgrade
Given an n by n integer matrix and a number of turns between 1 and 4, rotate the matrix clockwise by 90 degrees that many times, except that the entries on the main diagonal and the anti-diagonal stay fixed. Only the four triangular regions cut out by the diagonals rotate. Return the resulting matrix.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.