Monday, November 7, 2016

HackerRank - Spiral Message - NCR codesprint

Nov. 7, 2016

Problem statement

Julia spent over 4 hours to work on the solution, she made 15 submissions in the contest.

No. 1: first submission - score 4.49 of 20 (pass 4 of 14 test cases)


submission #2: (Score is 0.82 (full score is 20), pass 2 cases of 14 test cases.)


Julia's analysis after contest about the submission:
Submission #2 issues:

1. Repetition: Code is no good in structure, repetition code.
2. Structure issue: Counting mixes with string construction. Counting code duplicates 4 time. line 96 - 100
3. Base case: base case is not handled properly, one row, one column; one row will be counted twice.
4. Missing info: String split using # is avoided, just use count directly. But the spiral message is not correct.
5. Extra variablesrow, col two variable can be avoided, using startX, startY, endX, endY to calculate.

No. 3 submission

code review after the contest:
  1. The while loop - 115 - 119, but line 118, 119 redundant, part of first two lines.
  2. Base case - one row, one column do not work - count twice
  3. Add debug code - stringBuilder to tracker the string output - it is helpful, but unfortunately in the contest, Julia did not catch the error - starting point.
  4. Missing start time/ end time for submission above function comment, need to track time spent.

line 49 - 59 test function: 

if the testing() function, the program does something like string.CompareTo("xaa##ar#rswx#aa") == 0 (line 209 - 210). and then, Julia would have found the start point should be lower left-hand instead of up left-hand in the contest.


No. 15. Julia's submission - score 6.7 of 20



Editorial Notes:

Think about the problem writing. Good problem writing gives out the important information, directly/ indirectly, more than once, twice.

There are 3 times to catch up spiral message starting point bug.
1. First, by following the diagrams closely.
2. Read the word by word
3. Sample test case spiral message result.

Base test case failed - bug, need to think about Math induction proof, starting from base case, and then, assuming N is correct, prove N+1 case based on N and base cases. Detail see book:
Page 15 - mathematical induction vs  programming technique of recursion

Design talk:
Spiral message - a matrix

start point matters,
choices: start from 4 corners.






No comments:

Post a Comment