5 kyu
Rotate a square matrix in place
358 of 408fungairino
Loading description...
Matrix
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
python new test framework + random tests are required. updated in this fork
Approved
COBOL translation, with random tests (author inactive).
approved
No random tests in Python and Ruby.
Added in Python for latest fork
This kata should invalidate my solution.
Hey there, I just completed this one on Leetcode and thought I would grab some codewars points for it as well if it was on here.
I was wondering if someone could shed some light on my solution for me - while it does pass all the tests, am I not technically going against the rules of the problem by making another 2d-array? I know I got around it by doing "matrix[:] = res", but doesn't that kinda beat the point of the problem? All my test cases were accepted on both Leetcode and here, but I wanted some clarification on whether this type of thing was allowed for questions that state "Do not return anything, modify matrix in-place instead."
Cheers!
This comment has been hidden.
This comment has been hidden.
And the line that completes the major task is in the description. For a 5kyu kata, it shouldn't be.
The problem has shifted from "Rotate square matrix..." to "Modify array in place"
This comment has been hidden.
Really cool problem! Refreshed my matrix operations and learned a neat ruby trick all in one fell swoop! Thanks fungairino@!
This comment has been hidden.
@fungairino
,Although I kept getting timeout errors, it looks like my edits (I only added two backslash characters) actually were saved by Codewars.
Hopefully you don't mind the changes!
I'd like to build a JS version of this kata. Is there a way to do that and keep these two katas together as a translation bundle?
I allowed contributors if you want to add it yourself to this kata.
This comment has been hidden.
Unfortunately I dont see an easy way of not allowing building up a new rotated matrix and then replacing the original one unless we replace the data structure to some custom Matrix object.
You might want to indicate which test cases are testing the "in-place" requirement. Nice Kata!
Suggestion
It should be clearer how much extra memory is allowed.
Rotating in place isn't checked. The output should be done "in place", while even without change of input value (matrix value), the output is marked as correct, which is simply wrong. This is major issue.
Can you elaborate what you mean by "while even without change of input value (matrix value), the output is marked as correct"? I don't know how I would check that the user only modified the existing matrix instead of creating a new one. The way I wrote this kata assumes a bit of an honor code.
matrix = [[1, 2], [3, 4]] rotateMatrix(matrix) print matrix
this is how you should check whether rotation has been done in place (meaning: changing input data)
Oh I see, what you're saying. I'll update the test to make sure the input data is changed.
For the 4-dimensional test case, I believe [[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9,10,11,12], [13,14,15,16]] would be clearer than [[ 1, 2, 3, 4], [ 4, 5, 6, 7], [ 7, 8, 9,10], [11,12,13,14]]
Otherwise, a nice honors system challenge!
Oops, yea thanks for pointing that out!
In place means that I can't create additional matrices, but can use few scalar variables?
Sure, you can use a couple of scalar variables (to avoid finding the length of the matrix multiple times, for example).