Tuesday, January 17, 2017

Suffix Rotation - a test case tells the truth

January 17, 2017

Introduction
Julia had some study on Leetcode 17 - a phone number algorithm, one of studies is on stack/ queue implementation of the algorithm in May 2016. After more than 6 months, in January 2017, she worked on suffix rotation algorithm in the contest, she made a mistake to choose using queue instead of stack.

So, after the week code 28 contest, in 1 - 2 day, she studied suffix rotation's test case provided by hackerrank: a string "lcatqjejhpgkrkhnxsfyqlulncefeytykwnqbfmqaduldwhgwruwkdvojexefcmfrlfuzzcurjgnnbkskbzw", the code has issues related to out-of-memory, queue size is over 11,387,997, 10 millions, stop after processing first 12 chars "aaabbbbbccc", over one minute at least.
code with bugs is here.
Suffix Rotation C# practice, with a bug running out of memory.
working code is here.

Problem Solving 

Thank you, a small test case helps me to understand the issue again. Queue vs Stack, for phone number less than 7 digits, queue is still ok - not causing out-of-memory issue. But with string with length over 20, the problem quickly comes out easily.

lcatqjejhpgkrkhnxsfyqlulncefeytykwnqbfmqaduldwhgwruwkdvojexefcmfrlfuzzcurjgnnbkskbzw

Remember this test case, as a programmer, Julia has to work on a test case more often; build a good habit to figure out issues in the design with help of test cases, specially in any hackerrank contest. Kind of boring talk, let us talk about a song.

The solid Rock, corner stone or sinking sand

Julia has a favorite song she likes to sing along a lot of times, specially a lot of years ago (2000 - 2010) in Boca Raton

Related to being a hackerrank contest player, Julia has some hope, the test case can be her solid rock if she has weakness in the design, and flaws in thinking process.

The test case is the solid Rock, I stand;
All other ground is sinking sand, 
All other ground is sinking sand.

Code review study

Julia chooses to study more on phone number related algorithms.

1. Code review: Phone number.
2. Very good Dynamic programming explanation, read the phone number's code review by Google engineer.
3. Phone number code review - group of 3 digits with no lone digits.


At last, review algorithm code review made by a google engineer, click here.



No comments:

Post a Comment