Monday, September 26, 2016

HackerRank - world code sprint #7 - Gridland Metro

Sept. 26, 2016

Problem statement

 Julia spent over 8+ hours to work on this algorithm. She learned so many things, and most of important, she liked to train herself - strong determination, after 8+ hours, near 10pm, she was so surprised that she made full score 25 out of 25, because she started to adopt new way of thinking. She looked up her blog, and then find the idea:

  Avoid overcomplicate code

  from the blog

  So, she starts to practice advice she learned through reading, and then she enjoyed the great success on this problem solving.

  Will come back later to write more. More than 8 hours work, a lot of things to review.

   Come back on Sept. 27, 2016
1. submission 1: pass test case 1, score 0

 4 hours work, score 0; but the algorithm is working.

2. pass 3 of 30 test cases, score 1.67/ 25, 2nd C# practice.

3. score 1.67/ 25, 3rd C# practice.

4. score 4.17, pass 6 of 30 test cases, small progress, 4th practice.

5. try to pass any test case from test 7 - 30, failed once. 5th practice.

6. failed second try to pass test cases from 7 - 30, still score 4.17. 6th practice.

7. break through test case 7 -30, still failed, still score 4.17, 7th practice.

8. last try to break through test cases from 7 - 30, failed. still score 4.17

One thing for sure is that Julia has high standard now, she understands that it is important to continue to give up code, even write a new one,  if  code smells slightly.

Even if the code passes all test cases, but she likes to present code with good style.

Through the last 3 tries, she found several issues:
1. The bug she tried to fix is in different abstraction level, but stay in the same function. see line 218 - 222 of source code.

Code review under pressure was so exciting; Julia remembered the saying after 6+ hours continuous work - "avoid complicated code"; the function (line from 197 - 257 of source code ) is too complicated, doing too many things.

9. Score 25 of 25, more than 8 hours work - using LINQ, Lambda function, source code.

Highlights of change: break through test case 7 - 30

line 216: foreach (int row in sortedRows)  (section 8), source code.

The loop has the fatal weakness dealing with large, unknown data set, it leads to a unresolvable bug; In other words, collection

"sortedRows" can be filtered out more. Need to work on distinct row number.

line 212: foreach (int rowNo in distinctRows)  (section 9), source code.

Review after 6 month 

March 4, 2017

Julia reviewed the algorithm, and she was so surprised that she had to spend near 2 hours to relearn the algorithm, the code written in the contest had so many issues. She was happy to understand better how to write readable code after 3 months experience on

She wrote the C# solution and also asked the question. The blog is here and code review is here.

No comments:

Post a Comment