Friday, March 23, 2018

HackerRank NCR code sprint: Spiral Message

March 23, 2018

Introduction


I spent more than 30 minutes to review my own question on stackexchange.com, and I like to post an answer after 15 months. Here is the question I asked in January 2017.

Code review


I wrote the code again, here is the C# code. I will write an answer in short future.

1. change variable names to make it more meaningful.
 startX is changed to rowStart,
 startY is changed to colStart,
 endX   is changed to rowEnd,
 endY   is changed to colEnd.

2. Remove code related to check base cases like one node, one row, one column, set direction variables.

3. Add base case one node and one column break statement just after the first leftmost column.
4. Add base case one row break statement just after the second top row.


My last 3 month practice


The matrix spiral print is my most favorite algorithm, first in January I was interviewed and got low performance 1/ 4 problem solving rating. After that I tried to practice more than 10 ideas using Leetcode 54 discussion panel, I asked the question on stackexchange.com, and then i used the algorithm to interview more than 13 interviewees on mock interview platform. If I do learn something, I must learn from this algorithm.

Here are the links to look up. I still get organized by adding/ modifying the labels on blog platform.

Search by keyword: spiral matrix print, here is the link. Search using keyword: Leetcode 54: Spiral matrix, link is here.


No comments:

Post a Comment