Thursday, April 14, 2016

HackerRank: Matrix Rotation (Series 1 of 5)

April 14, 2016

Rotate array - HackerRank

problem statement:
https://www.hackerrank.com/challenges/matrix-rotation-algo

Spent hours to work on the solution, passed 4 basic test case, but still score 0 out of 80 points:

https://gist.github.com/jianminchen/4d719488e378aeb498d4cb363cbd1f7d

Just be patient. Study other's code:

https://gist.github.com/jianminchen/c234a238ea331ea9a037d603c37a6649

So, do not swap two nodes value, just save first node's value in a variable, and then, shift array kind operation.

Corner case is very simple. Julia wasted hours to work on poor design, try to avoid overwrite the value of arr[1][0]. Just use a variable to save it.

https://www.hackerrank.com/rest/contests/master/challenges/matrix-rotation-algo/hackers/Relentless/download_solution

So, changed my own code, with bugs to fix:  Int16 should be int, check Int16 max value 32767, whereas Int32 max value 2,147,484,647, less than 3 *10^9
https://gist.github.com/jianminchen/6e3ca88e8633ad8bace8387f154904df

only pass one case:
https://gist.github.com/jianminchen/12b58729c59e44a0d71d9f9c47bc937c

another practice: (more than 1 hour, still having bugs, score 8.89/ wrong answer)
https://gist.github.com/jianminchen/57572227dafe939060f7cc81b193cd9b

study the code here:
https://gist.github.com/jianminchen/6e2ca0ac395913646ed012c40c283e7f

https://gist.github.com/jianminchen/c0f91e5f5406c3dce35ce48c4c646c33

study forum:
https://www.hackerrank.com/challenges/matrix-rotation-algo/forum







No comments:

Post a Comment