Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
how to rotate a square matrix by 90degrees with O(1) extra space????
Posted 26-Feb-13 5:53am
LahariV306
Comments
joshrduncan2012 at 26-Feb-13 11:04am
   
What have you done to accomplish this so far? Where are you stuck?
Sandeep Mewara at 26-Feb-13 11:19am
   
Ditto!
Sergey Alexandrovich Kryukov at 26-Feb-13 14:15pm
   
This is one of those relatively tricky interview questions which mostly need some mathematical and logical thinking, not much more. I don't like such questions much, but it's not that bad...
OP just need to think...
I have only one advice to OP: don't give up. Not a rocket surgery, by the way...
—SA
Manfred R. Bihy at 26-Feb-13 16:07pm
   
You're really amusing me with your slightly "off key" idioms!
I'm not sure though if you're doing this on purpose or by accident, hmmmm.
;)
 
Sergey Alexandrovich Kryukov at 26-Feb-13 16:37pm
   
Thank you for asking, I'll gladly answer you, but I'm a bit confusing: which one, literally?
If this is "rocket surgery", this is intentional, and not my invention. Or are you talking about something else? What's "off-key"?
—SA
Manfred R. Bihy at 27-Feb-13 0:35am
   
The "idom" in question is "it/smth. is not exactly rocket science". So it's actually in science and not "surgery". A couple a days ago you wrote "rocker science", but I'm sorry to say I can longer find that comment of yours. I hope the question wasn't deleted.
 
[Edit]: Feel free to chastise me. I just googled "rocket surgery" and was astonished to find it really exists as a take on two metaphors concerning "Rocket Science" and "Brain Surgery". Sort of a malapropism if you like.[/edit]
 
Cheers!
Sergey Alexandrovich Kryukov at 27-Feb-13 0:50am
   
Well-known saying, in fact; unfortunately, I don't even remember where I picked it up.
By they way, this is not an idiom, but rather a meme... And a malapropism, yes.
Thank you for your interest to this matter. I really like a good to-the-point word... ;-)
—SA
Sergey Alexandrovich Kryukov at 27-Feb-13 0:53am
   
Wait a second, did you really write "rocker surgery" instead of "rocket"? Or did you misspell yourself? If so, it wasn't intentional...
—SA
Manfred R. Bihy at 27-Feb-13 1:53am
   
No, as I said, a few days ago you wrote "rocker surgery", but alas that comment is no longer to be found.
Indeed, it isn't an idiom at all since "rocket science" makes sense when translated to many languages (German for instance).
"Metaphor" was the word I was groping about for. :)
Sergey Alexandrovich Kryukov at 27-Feb-13 2:02am
   
Right :-)
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

See the matrix as a set of nested squares. You can rotate each square independently. To rotate a square by N positions, you can rotate it N times by one position. To rotate by one position, save one element to extra storage, shift the others circularly and put back the saved element.
A B C D E
P       F
O       G
N       H
M L K J I
 
- B C D E     A
P       F
O       G
N       H
M L K J I
 
B C D E -     A
P       F
O       G
N       H
M L K J I
 
B C D E F     A
P       G
O       H
N       I
M L K J -
 
B C D E F     A
P       G
O       H
N       I
- M L K J
 
B C D E F     A
-       G
P       H
O       I
N M L K J
 
B C D E F
A       G
P       H
O       I
N M L K J
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 2 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100