Last active
September 8, 2022 08:34
-
-
Save RaminMammadzada/f7e45e3724b997446a93306a155197b7 to your computer and use it in GitHub Desktop.
CodeSignal - rotateImage.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| a = [[1, 2, 3], | |
| [4, 5, 6], | |
| [7, 8, 9]] | |
| the output should be | |
| solution(a) = | |
| [[7, 4, 1], | |
| [8, 5, 2], | |
| [9, 6, 3]] | |
| Input/Output | |
| [execution time limit] 4 seconds (py3) | |
| [input] array.array.integer a | |
| Guaranteed constraints: | |
| 1 ≤ a.length ≤ 100, | |
| a[i].length = a.length, | |
| 1 ≤ a[i][j] ≤ 104. | |
| [output] array.array.integer | |
| [Python 3] Syntax Tips | |
| # Prints help message to the console | |
| # Returns a string | |
| def helloWorld(name): | |
| print("This prints to the console when you Run Tests") | |
| return "Hello, " + name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def solution(a):
a.reverse()
for i in range(len(a)):
for j in range(i):
a[i][j], a[j][i] = a[j][i],a[i][j]
return a