Problem statement:
https://www.hackerrank.com/challenges/matrix-rotation-algo
Study code:
https://gist.github.com/jianminchen/1c1c07b5454a43d493264c6db4444ea3
Because there are over hundred C# solution to review, Julia likes to go over them first, mark good solutions to study first.
1. jaygundy
https://www.hackerrank.com/rest/contests/master/challenges/matrix-rotation-algo/hackers/jaygundy/download_solution
2. pableFomenta - similar to code review #2
https://www.hackerrank.com/rest/contests/master/challenges/matrix-rotation-algo/hackers/PabloFomenta/download_solution
Ideas to study code submissions:
1. Study all submissions using JavaScript with full score.
30+ solutions
2. Study submissions - using filters:
Carnegie Mellon University, Pittsburgh(30+)
MIT ()
Stanford University
University of California, Berkeley
Amazon (20+)
Google (20+)
Facebook (5)
Facebook - Player-1
Look for code with good style and design ideas:
Facebook:
1. Java
Define Set function, line 65 - 69.
https://gist.github.com/jianminchen/5e7796bce5a9420472bec31a2cc6e30b
2. C++
line 25, int lt_corner - variable is very clear and meaningful
https://gist.github.com/jianminchen/d8843e292df6e9070e5f55c907ad0f69
3. C++
Matrix at most 300x300, so total size at most is 300*300*4bytes =
line 8: int M[300][300]
Declare a global variable - jagged array, the code is very easy to read.
Use the condition: n <= 300
https://gist.github.com/jianminchen/15ff14b51ab1c9f86084dbba4a036684
4. C
For any element in the array, use one for loop to rotate k steps. Very smart handling - code from
line 29 - 45, total 16 lines of code
https://gist.github.com/jianminchen/137807675ba27fd532ffaed4f98a68df
5. Java
Cannot believe!
https://gist.github.com/jianminchen/6e84dfcf2fb222d84900bda27687e6a1
Amazon
Java
6. Design a class: LinkedListLight, with an API - RotateBy(int steps)
https://gist.github.com/jianminchen/b7cb950b70563b56cb37909e72e0b48c
Standford:
JavaScript
7. https://gist.github.com/jianminchen/ae14bc0d764240d03831e6429337199a
No comments:
Post a Comment