Monday, November 7, 2016

HackerRank NCR codesprint - Spiral message - After the contest

Nov. 7, 2016

Problem statement


Previous blog about 15 submissions in the 48 hours contest.


After the contest, Julia downloaded all test cases, input/ output, she played with test cases, after more than 30 minutes, she finally figured out her major issue on the problem solving.

From the first 3 lines of problem statement:
The message originated as a single line of one or more space-separated words, but it was encoded into an  matrix as a clockwise spiral starting in the lower left-hand corner

Julia did not pay attention to the start point, lower left-hand corner. All her works are from up left-hand corner instead by a mistake

So, there are 4 corners:
up left-hand           up right-hand
lower left-hand      lower right-hand

Work on the sample test case: 
3 5
a##ar
a#aa#
xxwsr
The output of spiral message:
xaa##ar#rswx#aa

She did work on the coding in the contest, her output starting from 'a', not 'x'. In other words, sample test case's spiral message - her understanding and output: 
a##ar#rswxxa#aa


So, in the contest, Julia has to train herself to read problem statement more carefully. 

Ideas:
1. Write down all inputs
2. Make a check list
3. Make her own notes, do some research about the algorithm
For example:
1. a spiral message
2. clockwise
3. starting from lower left-hand corner
4. Not from general case - upper left-hand corner
5. ...


She started to work on the algorithm from 11:00am, Saturday, and then, in the evening, from 11:00pm - 1:00am, she came back to work on the algorithm, she read the problem statement again and again, but she did not notice the starting point - lower left-hand corner. 

Actionable Items:

Do not spend more than 1 hour to write code in the contest; go back to read the problem statement again and again; draw your own diagram - anti-clockwise. 

It is easy algorithm. Julia stumbled on easy algorithm so badly. 

C# code after contest - bug-free, clock-wise starting from lower left-hand corner


Year End review:
Review previous work on array manipulation:

1. Previous work on rotate of array

2. array rotation

3. array rotation (II)

4. array rotation (III)

No comments:

Post a Comment