본문 바로가기
CodeSignal/Interview Practice

[Arrays] rotateImage - Amazon, Microsoft, Apple

by 벤진[Benzene] 2020. 5. 29.

Problem:

Note: Try to solve this task in-place (with O(1) additional memory), since this is what you'll be asked to do during an interview.

You are given an n x n 2D matrix that represents an image. Rotate the image by 90 degrees (clockwise).

 

Example

For

the output should be

-Summary-

1. Reverse the matrix first

2. Transpose the matrix to move around the elements. The element will be rotated with 90 degrees. (Clockwise)

 

Leetcode 에서 봤던 똑같은 문제가 나왔다. Reverse() 함수와 matrix의 transpose 를 이용하면 쉽게 풀수 있는 문제다.

 

모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]

https://codesignal.com/

댓글