Monday, April 11, 2016

HackerRank: String Calculate function (III) - Suffix array (II)

Plan to work on LCP array later. 

Use C# implementation of suffix array in blog #1, still time out on hackerRank

SuffixArray implemented in C#, by MSFT, Google employee; Julia has to catch up C#, and learn 
how to write beautiful code like this:

Study C# code how to implement IEnumberable interface in suffixArray code:

how String.Compare api is designed
Julia also takes some time to work on suffix array, and get some drawing about suffix tree, and play with two case:
aaaaaa, 
banana, 
abcabcddd, 
For those two strings, what are suffix tree? Get so close to concrete examples, draw diagram, run test case, study code, and compare to other C# submission. 

Focus on how to find the range of suffix array to fit in the pattern: 


Walk through the examples how suffix array is implemented in C# code:


public SuffixArray Search(string str)

        {
            if (m_lower > m_upper)
                return this;
            // Otherwise search for boundaries that enclose all
            // suffixes that start with supplied string.
            var lower = Search(str, c_lower);
            var upper = Search(str, c_upper);
            return new SuffixArray(m_text, m_pos, lower + 1, upper);
        }

Example 1: string "aaaaaa", pattern string "aaa". 
suffix array {5, 4, 3, 2, 1, 0}
suffix string:
a
aa
aaa
aaaa
aaaaa
aaaaaa

suffix array is acending order, string.Compare("a","aa")  = -1, string.Compare("aa","aa") = 0. string.Compare("aa","a") = 1

suffix array is implemented using interface IEnumberable. 
we try to find 2 index, low, top, 
index = 1, "aa", string.compare("aa", 0,"aaa",0, 3) = -1, 
now, we need to find top index, 
assume that "abc" is in the array, string.compare("abc",0,"aaa",0, 3) = 1, first one is >-1, stop; 
aaa, aaaa, aaaaa, aaaaa, all computed value of comparison = 0 since we only check substring with length 3. 
So top index is 5. 
So, count of substring "aaa" is calculate by top index - low index + 1
top index = 5, 
low index = 1+1
so count = 4. 

Try to figure out how this binary search algorithm is used to calculate low index and top index, called twice, comparison value for low index = 0, for high index is -1. 
In other words, find last one is smaller than "aaa", and first one bigger than "aaa". 

Example 2: "banana", pattern "ban", 
 Read the content in the blog first:
http://www.geeksforgeeks.org/pattern-searching-set-8-suffix-tree-introduction/

And then, 
suffix strings:
banana
anana
nana
ana
na
a

Sort them ascending order:
a
ana
anana
banna
na
nana

pattern string "ban", first to find a string which is last one < "ban", -> "anana", index 2, "ana" < "ban"
and then, find first string which is bigger than "ban", only comparing length 3 substring, 
"banna" = "ban" based on comparison (substring len = 3), so
"na" - index = 4 > "ban"
2+1 = 3, 
top index = 3 
so, ban pattern match is  3-3 +1 = 1



"Work on Examples First" - Practice feels good!

The LCP-LR array helps improve this to O(m+logN)O(m+logN), in the following way


LCP array reading
https://www.hackerrank.com/challenges/pseudo-isomorphic-substrings/topics/lcp-array

https://en.wikipedia.org/wiki/LCP_array

Follow up: May 4, 2015
Read the article:

June 10, 2016 - Plan to spend 30 minutes to read the slides:

Julia, learn something here from the blog:

http://decomplexify.blogspot.ca/2014/07/lcp-array.html?view=classic

Sunday, April 10, 2016

HackerRank: String Calculate function (III) - Suffix array

April 10, 2016

Time spent: 9:00pm - 11:40pm

Problem statement - string calculate function on Hackerrank 



KMP Algorithm, Rabin Karp Algorithm, Finite Automate based Algorithm, Boyer Moore algorthm. 

All of the above algorithms preprocess the pattern to make the pattern searching faster. The best time complexity that we could get by preprocessing pattern is O( n ) where n is length of the text. 

So, Julia second try still failed, no progress on time out issue. 

Now, Julia read the blog and learn suffix array / LCP array in next hour 9:00 pm -10:00 pm:

A suffix tree is built of the text. After preprocessing text (building suffix tree of text), we can search any pattern in O(m) time where m is length of the pattern. O(n) -> O(m), solve timeout issue

HackerRank: string function calculation (II) - string algorithm - Boyer Moore Algorithm

April 10, 2016


  Problem statement:

https://www.hackerrank.com/challenges/string-function-calculation

  Time spent: 3:40pm - 4:40 pm

First hour work, score 8.9 out of 80 points. 
The solution: 
https://gist.github.com/jianminchen/09c77ba32b156f765b4debb2bccba0c8


Brute force solution:

pass one test case: aaaaaa, return 12,

use Boyer Moore Algorithm, still time out:

time spent: 8:00pm - 8:45pm 



copy Boyer Moore algorithm code from the webpage:

convert the class from Java to C#. 

Julia second try:  (time out issue - Boyer Moore Algorithm does not help!!!)




HackerRank: string function calculation - string algorithm - Brute Force Solution

April 10, 2016

  Problem statement:

https://www.hackerrank.com/challenges/string-function-calculation

  Time spent: 2:40pm - 3:35pm 20 minutes to think, 20 minutes to write down in C#

Understand the problem, so, here are her thoughts:

Brute force solution:

pass one test case: aaaaaa, return 12,

failed test case:
abcabcddd,
wrong answer - Easy fix, index error on the loop

score 8.89/ 80

one test case: wrong answer
All other test cases time out

https://gist.github.com/jianminchen/09c77ba32b156f765b4debb2bccba0c8

Need to work on KMP, or Boyer-Moore algorithm, see how to make HackerRank happy, score more points.

http://www.cs.tufts.edu/comp/150GEN/classpages/BoyerMoore.html

blog:
http://juliachencoding.blogspot.ca/search/label/string%20functions%20review








Saturday, April 9, 2016

Mental skills to help players

April 9, 2016

  Competitive programming is like tennis sports. So, when Julia blogs her practice on problem solving on HackerRank, she also likes to journal her practice, for example, log time spent on.

 Here are the notes taken:

Mental Skills to Help Your Players

https://www.youtube.com/watch?v=E8-7LA9-UOY

Journaling practices/ Matches (27:24/39:58)
  • Date, Time, Type of Play (Practice/ Match)
  • Opponent ( if applicable)
  • Length of Time
  • Feeling
  • Emotions
  • Focus/ Concentration
  • Nutrition/ Hydration
  • 3 things you did well, 1-3 things to improve

Goal Setting:

  • smart goals
  • LT and ST goals
  • Set for practice and competition
  • Write them down!!!
  • Reflect on motivation and you commitment to these goals
  • Evaluate, assess, adjust goals as needed
Reference:

USTA Mental Skills and Drills Handbook

Action item: Read the book 20 pages. Take some short notes as well.





HackerRank - count string (V) - C plus plus solution

April 9, 2016

Spend one hour (4:00pm - 5pm) on this C++ solution, talk about the code and implementation:

C++ solution


Julia needs to figure out the design:

For test case:
1
((ab)|(ab)) 2

The design is to construct a graph, NFA, and then, convert it to DFA, and the count how many ways.

It is hard to teach yourself through HackerRank a solution; so, Julia likes to catch up by some reading. Searching the web ...

Read some blogs to get some help:

1. Not very useful


2. Try to read it in 10 minutes

ucsd.edu lecture notes - homework solution

3. Another reading:  

30 minutes reading - excellent content! 

Julia learns better after she invested 8 hours to try to understand a problem, by playing with hackerRank. 

princeton.edu lecture notes - regular expressions


Julia, try to memorize content on the above slides.

Learn quickly from lecture notes, a diagram for NFA:
((ab)|(ba)) 2




HackerRank: count string (IV) - JavaScript

April 9, 2016

 Spend some time later to go over this JavaScript solution, score 80 out of 80.

https://gist.github.com/jianminchen/4d5d2f77d0e23e424a0953aaf4e4276e


HackerRank: Count string (III)

April 9, 2016

 Problem statement

 Solution to study:

Julia's C# practice with bugs


 The code has time out issue, wrong answer, and it only scores 3 out of 80.

code source:

https://www.hackerrank.com/casaro

Statistics:

Time spent:  1:00pm - 3:00pm
Go through test cases

C# code to study, also show C# source code here.



April 10, 2016

Action items:

Need to think about in computer theory, NFA, DFA, and argue that the above solution in theory has flaws.

Follow up after 12 months


Julia checked the blog statistics, and the blog has a lot of views recently. So, she reformatted the blog style and she will review the algorithm very soon, and also post a question on code review.

HackerRank: Count strings (II)

April 9, 2016

Julia likes to have some adventure and just get into other people's solution, and quickly learn something in next 20 - 30 minutes.

Problem statement:


Statistics: time spent:  11:22am - 1:00pm

Here is the solution from a programmer working in Apple:

Code to study by Apple engineer


Comments after reading:

1. This problem is about DFA, NDFA, those content learning in Formal Language, how to build a compiler.

Friendly remind - great time to study formal language, first time for computer science master degree, score C in the course, and then in 2001 to prepare Ph.D. qualification example, Julia spent a lot of time to read the textbook again.
 

2. The string parsing is more complicate, '(', ')' should be treated as operator, and then, you can build up something.

3. Read the wiki webpage to quickly refresh knowledge
https://en.wikipedia.org/wiki/Deterministic_finite_automaton

4. Play with Visual studio and also the code - debug and run through the test case 20-30 minutes:
(ab)|(ba)  2
((a|b)*)  5

5. And put some diagram on the paper, take picture, post here and see if you can draw the state diagram for this machine.  ( 20 - 30 minutes)

Julia likes to read the code, and also debug the code;

Some facts:

1. she learned Formal language in 2001 to prepare Ph.D. qualification exam, but she never did spend time to work on an concrete example, debug the code to see how it is designed.

2. the code is well designed, and also beautiful code to read;

It is hard to figure out how to construct the Ndfa, but reading the code, Julia, you should figure out the design:




HackerRank - String algorithm - Count Strings (I)

April 9, 2016

Problem statement


Category: Difficult problem

Spend 25 minutes to think about problem, and then will get into other people's submission, and see what should be learned.

10:30 am - 10:55 am

Spent 25 minutes to think about the problem.

Try to express the expression using binary tree, like 1 + 2 * 3 problem using a tree.

So, ab can be express as a tree:

operator .
/       \
a       b


 a|b
operator |
/           \
a            b

a*
put * as parent node, and a is left child of operator node *

(a*)5
put 5 as the parent node of operator *

Structure the input as tree structure, and then, define different class - concatOp, orOp, starOp

Read the expression from left to right, and then, put it into data structure like a stack, and then, parse it, store it in the binary tree.

April 10, 2016 2:32 pm 

This is a graph problem, and also, the NFA, DFA problem. Julia, you are lucky to review the problem. Spend some time in the short future to go over code, give yourself a graph coding experience.

Elizabeth Holmes's Top 10 rules for success

April 9, 2016

 Watch the video:
https://www.youtube.com/watch?v=iwKs-eoPM-Y

 Take some notes:

1. Find your way
Love things you are doing; you will get back up after you are knocked down.

Talk about concept about 10,000 rule, you go so deep about something; you cannot be expert on it; when  you love it so much, then you do not let it go. That is winning about.

In other words, fail over and over again until you succeed.

2. Focus on your mission

3. Build people

4. #Believe

5. Don't have a backup plan

6. Embrace failure
Open to failure, fail over a thousand times to get it work at 1001th time. Determination to make it work.

7. Surround yourself with smart people

8. Don't do it for the money

9. Weather the storm
Big waves come and go, you are there for the reason.

10. Make a difference

June 1, 2016
Billionaire to nothing.

http://time.com/money/4353658/elizabeth-holmes-theranos-broke/?xid=frommoney_soc_socialflow_facebook_money


Friday, April 8, 2016

Article reading: Get that coveted tech interview

April 8, 2016

http://utsavized.com/getting-that-coveted-tech-interview/

Revamp your resume
organize, and make it simple and clear.
list your accomplishments in brief and succinct sentences. Include facts and numbers whereever applicable.

Make sure you have the right things on your resume

List out your personal projects

If you are prepared to devote a significant amount of hours each day, sacrifice your weekends and hangouts, to almost redo your entire Bachelor’s degree all by yourself, then that attitude and perseverance will undeniably get you through. And at the end, even if you don’t land the job, trust me, you will become a much more competent engineer than you are right now.

Julia's thought: It is true, practice makes difference

More reading:
https://www.quora.com/profile/Mohsin-Ali-19

https://drive.google.com/file/d/0B9lkfT8_oB3fdTRXUS1xZzBZT2s/view

Article reading: How to get hired at Microsoft

April 8, 2016

 Doing some research on high-tech companies interview process.

http://landthatinterview.com/microsoft/how-to-get-hired-at-microsoft/

one of the top 100 places to work across all industries.

Understanding how to navigate the screening and hiring process is also important.
1. Apply for jobs that you are qualified for
2. Don't be intimidated by job listings
hired for long-term potential

3. The inside angle 
Microsoft gives a lot of weight to references from current employees. 
not single monoculture, more like a conglomeration of many smaller companies. 

4. Apply for multiple jobs, but keep it targeted. 

Julia's thoughts: 
1. Need to study C++
2. Need to take some crash courses for distributed system, and other areas. 
3. Every month spend 5-10 hours to cover some topics - study and get educated.  

5. Be persistent
6. Make a good first impression 
It's not just about you - team effort, not lone cowboy coder. 
It is about you - be specific about contributions you have personally made toward the success of previous projects. 
7. Understand the interview process

Nov. 24, 2016
1. https://blogs.msdn.microsoft.com/ericlippert/2004/04/15/writing-code-on-whiteboards-is-hard/

2. http://sellsbrothers.com/tagged/interview

Article reading: Microsoft Interview Process

April 8, 2016

Doing some research. It is fun to write down what you read, and then, come back later to review again and again.

Take some notes from the following articles:

Land that interview
http://landthatinterview.com/microsoft/the-microsoft-interview-process/

Facts:
1. Microsoft is really structured like many small companies internally, each with their own recruiting teams.
2. a screening phone interview, also show that you are better than 90% of the hundreds of others

Advice for phone screen:
1. Talk talk talk in the technical phone interview, keep it on topic and don't try to steer the conversation, verbalize what you are thinking.
2. Second, have fun!
3. Ask a lot of questions and don't make assumptions. If you make assumptions, explicitly state that you are doing so and get the interview to buy in to those assumptions.
4. The hiring manager likes to know that the person will be engaged and productive.

Advice for interview in person:
1. 1 in 10 for a particular position -
2. proactively engage the recruiter
3. business casual attire, not a 3-piece (awkward)
4. first 3 interviews. May be interviewed by a developer, a test manager, a program manager, and the hiring manager. Finish before lunch time.
5. the as-appropriate interview - last regular interview will be over at round 4:00 in the afternoon.

Julia's comment:

 Julia likes to do some research on Microsoft interview process. Now, she knows that Microsoft does not practice interview as Google does, using hiring committee. 




Thursday, April 7, 2016

JavaScript - slide show case studies

April 7, 2016

Work on JavaScript, Css, html on picture slideshow.

Here is the list of sample code Julia chose to study.
1.
http://robertnyman.com/picture-slides/

Mental skills tip:
Julia read google employer's code about slideshow, how the code is structured and commented, and then, she found her issue.

Learning JavaScript, first thing, is not afraid to break things, learn the grammar first; Fix the style. She spent 3 hours to fix the style problem of her slideshow JavaScript legacy code. Make sure that the style is readable.
For example:
return a=1, b=1, c=1, d=1;
readable style:
return
a=1,
b=1,
c=1,
d=1;


2. page slide show 





3. Demo - 

source code:


Tips learned on April 8, 2016:

about comma in the JavaScript code: return statement:


understand return statement with multiple , commas

4. read more about JavaScript


http://www.itsalif.info/content/good-javascript-practices



Action item: 


Share the slideshow JavaScript as well. Make it more readable, using meaningful variables. 








Distributed System - study time

April 7, 2016

 Plan to study "Distributed System", get updated on this area.

 http://goo.gl/5BX1ND

 Take some notes.

 And read an article:

 https://www.cs.cmu.edu/~dga/15-440/F12/p3.pdf

Action item: next week
1. Spend 2+ hours to go over the lecture notes
2. Get rough ideas what are the big concerns in distributed system. (2+ hours)

Tuesday, April 5, 2016

HackerRank articles - reading time

April 5, 2016

 Julia's favorite articles on HackerRank:

 Recently, Julia starts to read articles on HackerRank, and she likes to take some notes:

 1. 8 ways to reduce bugs while coding
   http://blog.hackerrank.com/8-ways-to-reduce-bugs-while-coding/
  Tools: Findbugs - Java code, GetExceptional - Ruby apps, Selenium - web browsers

   unit tests & integration test/ use Tools / Compiler warnings / Code Review / Logs / Use existing libraries / Pseudo code / Avoid distractions

   Julia's thoughts:
 1. Write a small function
 2. Check variable scope - limit scope to minimum
 3. Design concern - make it easy, so every one can tell there is no problem.
 4. Push the coding problems to compile time not running time
 5. Document the test case above function, precondition/ post condition
 6. Have a lot of ideas to solve one problem, then, choose any one, you can write code right away
 7. Think about maintenance, use data structure, such as Array, go through loops - use iteration

    Recently, in March 2016, Julia uses a loop in JavaScript to add onclick() event - callback function; and then, finds out the variable i - iterated value is always the last one, not like C#,  and then, she figured out using closure concept; she started to write her first closure variable for real work. She got so excited. You can avoid using closure to finish a project, but when the code is reviewed the expert will know your strength - you never develop the muscle! Your code is like a fat, not a muscle.

   Push yourself to make the code most efficient mode first, and then, stay out of your comfortable zone; learn to be a good critic.

 2. Great article about learning
 http://blog.hackerrank.com/establish-yourself-expert/
 10% reading -> 20% Audiovisual -> 30% Demonstration -> 50% discussion -> 75% Practice doing-> 90% Teach others

 maximum learning happens when to "Teach others"

 Julia's thoughts:
  In 2015, Julia spent days/ weeks/ months on JavaScript learning, books reading, code snippets practice, video watching; But, in 2016, when she reads so many JavaScript submissions on HackerRank, she suddenly noticed that people are so good at JavaScript language, use it to solve daily simple algorithm problem, maybe as a hobby. She knows that it is also urgent to catch up JavaScript.

 3.
http://blog.hackerrank.com/programming-interviews-techniques-tips-by-gayle-laakmann/
  1. Simplify the question
  2. Create  assumptions
  3. Solve for simplified case
  4. Finally, generalize your answer

  Smart, write good code, who care about writing clean code

 4. Promoting Coding Culture in you campus
http://blog.hackerrank.com/promote-coding-culture-campus/
  self learning - MOCCs like Udacity, Coursera, edX
  Inculcate the habit of reading

 5. A stronger Programming Culture for India
 http://blog.hackerrank.com/stronger-programming-culture-india/

 HackerRank clubs
 Self learning attitude
 Rote-based education system has been detrimental
 Facts: IT graduates, only 25% are employable (as per Nasscom)

6. http://blog.hackerrank.com/how-to-crack-microsoft-interview/
 Arrive at the answer  (not just about arriving an answer)
 How you approach the problem (a lot about how you approach the problem)
 Your clarity of thought
 How you backtrack when you are stuck
 How you use the hints given to you.

Julia's thoughts:
Do some self-evaluation:
  1. Code skills - do you write a lot, read a lot of code recently? Warm up definitely helps.
  2. Do you like to solve the problem or not?
  3. Do you have some rituals to help you solve the problem?
For example, if you are so nervous, cannot think/ write as normal, what do you do?
Julia's answer: Find a simple test case, work out the design/ coding first.

  4.  Can you tell the problem difficulty level? Easy, medium, advanced  or difficult?
  5.  What kind of person you are in programming style? Are you a hacker?
  6.  How often do you practice problem solving?
  7.  What kind of tools you are using? Do you use HackerRank?
  8.  How many  peers you have - mock interview?
  9.  How often can you get some code screening? code assessment?
 10. Do you stay on the current moment or think about consequences? mental skills.

7. Productivity tips for programmers
http://blog.hackerrank.com/productivity-tips-for-programmers/

 1. write Unit test for higher productivity.
 2. Practice your programming.
 3. Use libraries and help improve them.
 4. Read code and technical stuff.

Julia's thoughts:
1. Julia did not find things exciting to do after work from 2010 - 2014, she found out that she does not develop strong interest, long term effort on somethings except tennis sports. So, she started to make change; Now, she likes to solve coding problems, and also she reduces a lot of stress as a developer. She knows a few more way to make the apps run good, easy to maintain.


Algorithm, Rotate matrix nxm clockwise 90 degree

April 5, 2016

  Write an algorithm to rotate matrix nxm clockwise 90 degree.

  Use no compiler, no Ctrl+C, and then, time complexity analysis:

Here is the code Julia wrote, she thought about the swapping strategies:
1. swap multiple times
2. leave four corners as is, swap four corners seperately.

https://gist.github.com/jianminchen/e489cf7a490ac426eb50b4300890387d

/*
April 5, 2016

NO ctrl+C copy

matrix nxm rotate clockwise 90 degree

do it in place
*/

 public static bool rotateInplace90ClockWise(int[][] arr)
        {
            if (arr == null || arr.Length == 0 || arr[0].Length == 0) return false;
            int n = arr.Length;      // row
            int m = arr[0].Length;   // column

            if (n != m) return false;

            // we need to start loops

            int start = 0;
            int end = n - 1;

            while (start < end && start < n / 2 && end < n / 2)
            {

                // top with right swap - left the terminal point untouched
                // left to right <- row
                // top to down   <- column
                for (int i = start + 1; i < end - 1; i++)
                {
                    int currx = start;
                    int curry = i;

                    int currx_col = i;
                    int curry_col = end;

                    swap(arr, currx, curry, currx_col, curry_col);
                }

                // now, top down, we need to cross swap

                for (int i = start + 1; i < end - 1; i++)
                {
                    int currx = start;
                    int curry = i;

                    int currx_down = end;
                    int curry_down = end - i;

                    swap(arr, currx, curry, currx_down, curry_down);
                }

                // left and top swap
                for (int i = start + 1; i < end - 1; i++)
                {
                    // left part
                    int currx = end - 1 - i;
                    int curry = start;

                    int currx_top = start;
                    int curry_top = i;

                    swap(arr, currx, curry, currx_top, curry_top);
                }

                // and then, rotate four corners
                // 1, 2
                // 4  3
                swap(arr, start, start, start, end);
                swap(arr, end, end, start, start);
                swap(arr, start, start, end, start);

                start++;
                end--;
            }
            return true;
        }
 
       private static void swap(int[][] arr, int x, int y, int x2, int y2)
       {
           int tmp     = arr[x][y];
           arr[x][y]   = arr[x2][y2];
           arr[x2][y2] = tmp;
       }

https://gist.github.com/jianminchen/e489cf7a490ac426eb50b4300890387d

time complexity: since every node in the matrix at most swaps twice, so the count of swap is O(n^2)

Sunday, April 3, 2016

HackerRank: string algorithm - Reverse Shuffle Merge (IV)

April 3, 2016


C# solution:

https://gist.github.com/jianminchen/346970ad058d64041ab7b8cbe9ecb495

Read the code, and talk about the ideas:
Best way to explain the algorithm - greedy one, the following, is to take away reverse, and also merge two parts (these are noisy!), work on a string, simple test case, how to construct a string with minimum lexically value, using stack to do greedy design, and also allow the back and forth two ways to optimize.

Here is the simple example:
1. string a2b2c2, for example, aabbcc, so abc is shortest one.
For string bbccaa,
first b, put in stack, second b, have to skip; and then, c is coming,
'c' > 'b', push c to stack, so stack is like this
b
c
and then, second c, skip it; now 'a' is coming,
'a' is bigger than 'b', but b does have any number to skip; need to put 'a' in anyhow.

the output will be "bca";

2. Try another one:
babcac
First one, b, go into the stack:
b,
meet a, and then, 'a' <'b', because b still have one to skip, so pop out b, skip the b, push 'a' in the stack;
Now, another b is coming, we have to hold one b in output, push it in the stack:
b
a
And then, c is coming, push it in c.
c
b
a

Now, a is coming, skip it; c is coming, also skip it.

the result is 'abc', smallest one in lexical sense.

3. Try third one:
work on first test case, make small change. move bbccaa, one of b, so the string is ccbaab,
c - put in the stack
c - skip it.
b - compare to stack top, b ( b has one left to skip);
so b into stack
b
c

c- second c, skip it
a- compare to the stack top: b
'a'<'b', still 'b' can skip one, one more is coming
pop up b, push a in,
a
c
and then, last char 'b' into stack
b
a
c
the output is "cab"

The question is to ask yourself, do you have genius to design it at the beginning, called thinking about in stack to cover mistake in greedy approach! Julia has no clue right now, she spent 9 hours to take this lesson. Backtracking is better term for using stack in the design.

April 5, 2016
Go over a2b2c2 case, the lexical smallest substring (Julia's first practice):
bccaba,
visit first 'b', skip 'b', because a has 2 of them to visit
visit first 'c', skip 'c',
visit second 'c', cannot skip, has to take it. Now, best one is starting from c, of course it is worse than the one starting from 'b', such as "bca".

So, greedy algorithm is to take what ever you can, and then, backtracking, make it smaller iteratively.
--
code source:  a box employee



HackerRank: string algorithm - Reverse Shuffle Merge (III)

April 3, 2016


Study the code written by some one in Google, need to get the idea how it is designed. It should not be difficult, since I already worked on this problem over 10 hours.

https://goo.gl/Rbh3B4


up to April 3, 2016
statistics:    1300 score 50.00 
Julia score rank:  1403
C# rank: 58

10-000 hour rule

April 3, 2016

  Share this article:
http://goo.gl/jnQ3qf

 10,000 hour rules - it is encouraging, keep going; learn to be mental strong; Do not get nervous when you are in trial.

 To entertain this 10,000 hour rule (better grammer: “10,000-hour rule”), Julia make a rule for herself, as a software programmer: called a new explainable variable or function rule - when you want to use Ctrl+C; or short name: Ctrl+C rule.

 This rule is for fast coding, people want to be a hacker. Let hand typing catches your mind quickly.

Saturday, April 2, 2016

Practice difference: How top sports player practice?

April, 2015

The best way for a software developer to take a break, is to study something else; let me propose an idea for myself today, and see if I can make a good shot or not.

See how top tennis player Male/ Female structure their practice? :-) Just kidding, I can only observe a few things as a player over 300, maybe, 500 hours.

Julia likes to study tennis teaching video, she learns a lot how to make a talk 2-3 minutes on a specific topic through coaching video.


Eugenie Bouchard - Fear Less

https://www.youtube.com/watch?v=4MVb3SR2yNA

https://www.youtube.com/watch?v=5YWdkxMQA6s

Li Na
https://www.youtube.com/watch?v=Qewi-SB5hWU

Novak Djokovic 

https://www.youtube.com/watch?v=HuWL65vrTJU

Murray's practice and his coach -
https://www.youtube.com/watch?v=YtvQRq0FvNI

https://www.youtube.com/watch?v=zR0U7wl213I&ebc=ANyPxKpEc8T3E79_tAtkvdPDj8KjfbAmn05rGWxNHe3BI7RzXCaZB24KHMMmRjUmTdSxsAgyZ60CP967G21vbREU5Pd3eFahuw

Overhead, and then, from forehand -> anywhere, receiving, and then, serving.

Just watch the hitting partner - the helper, how he can follow the instruction, last minute, when Novak calls wide, how the helper can place the tennis ball wide for him to receive.

Julia, you pay more attention to how they are focusing on training, and other technical things. Julia likes Novak using hand language to communicate to switch courts.

https://www.youtube.com/watch?v=ausQH8y3nQY

Hitting partner told Novak hitting outside - long just one inch.

Drills - Julia's favorite drills - double alley drill
2014 USPTA Tennis Teacher's Conference in New York City
https://goo.gl/bztNNE

Julia likes to organize some activity with sports to encourage people moving/ exercise, a lot of ideas for people in office, church etc. Julia loves the teaching how to do things on the court.
https://goo.gl/KD8RHa
Great teaching - medicine ball usage, foot work, forward to the ball.
https://www.youtube.com/watch?v=zpldQqYz2RE

plan to watch:
Mental skills for your players
https://www.youtube.com/watch?v=E8-7LA9-UOY

A few verses to memorize, every top tennis player loses, but still continues:
Genie Bouchard 2014 Montage - Good music always is welcomed! "In the Air Tonight" I want to be next version of me, not other person. What a good statement! 
https://www.youtube.com/watch?v=JZJ8K5857dk

Lyrics:
http://www.azlyrics.com/lyrics/philcollins/intheairtonight.html

HackerRank: string algorithm - Reverse Shuffle Merge (II) - next - forming a partial correct idea

April 2, 2016

  Problem statement is here  

  Introduction


Julia likes to share her experience, advance level on HackerRank. It is not bad in the weekend, spend 2 hours messing around the ideas/ hackerRank, come out a clear greedy algorithm. The hackerRank definitely helps Julia to shape her idea from start to end.

Practice talk 


  First two hours work - failed twice, detail here in the blog.     

  Here is the idea after 2 hours intensive work:
of course, "abc" is the smallest one in lexicographical order, but the possible string formats:
  *a*b*c*, not *abc*, now * means any number of any chars.

 Let us count how many of a, b, c can be skipped when we do linear scan of a string.

 Now, it should be very easily to introduce greedy algorithm.

 For example, if linear scan from left to right, visiting char b, then, we have to check how many b's left can be skipped, if it is bigger than 0, we have to check any char before b has anything left or not. For example, if a still has some number left to skip; we hold on b, just skip current b.

 Otherwise, count current b into the string we are looking for, and decrease the number count of b (recording how many b can be skipped).

Use an example to explain:
  a2b2c2 case,
 ba*, the half should be a1b1c1,
 so, skip first char 'b', since greedy algorithm / let 'a' go first.

 Give it a try, implement the idea:

 Some statistics: advanced algorithm 4+ hours - A mountain - "Sea to sky Gondola" to climb

Spent 9:47 am - 11:47 am, wrote code, but still failed most of case; only pass "eggegg";
Hard to concentrate, and think about the issue - this reverse is tricky!

Here is the C# solution - 3 rd failed try. Code is here.

Baby hacker is crying, still score zero: 4 hours work. Code is here.

Now, it is 1:47 pm, another 2 hours with music, the code was submitted, now score 16.67/ 50. Still need to work on more before Julia plan to read other people's solution:

Some statistics: advanced algorithm 6+ hours - A mountain - Sea to sky Gondola to climb. Code is here

Need to stop, go to enjoy outdoor activities!

Baby hacker is showing off her baby steps, the report of test cases pass/ fail on Hackerrank is here.

Try to fix the error, give up - the design has another flaw,
test case:
djjcddjggbiigjhfghehhbgdigjicafgjcehhfgifadihiajgciagicdahcbajjbhifjiaajigdgdfhdiijjgaiejgegbbiigida
i=50, s[i] = 'g', the design let 'g' skip, but
i=52, s[i] = 'i', 'i' has to be added to the output, no more skip.

<-  Julia, think about stack, use some data structure to do reverse work <- such a great workout! Release all my stress and headache, and be humble!

5:12 pm, statistics: Another 3 hours, total: 9+ hours 

Follow up 


May 3, 2017

Thursday, March 31, 2016

HackerRank: string algorithm - Reverse Shuffle Merge (I) - First step: Failed twice

March 31, 2016

  Problem statement is here.

 Introduction


 The algorithm is in advanced category. 8:17 am - 10:08 am. Document 2 hours work as a hacker, Julia. First time, Julia thinks that hacker is a good name!

 Practice Talk


Start from 8:19 am, 9:18, tried twice, passed one test case, failed others with wrong answer;  then, need to pay attention to reverse string word.

Spent more than 20 minutes to think, but could not figure out the solution. Have to stop here. Write down the analysis first. Come back later.

The naive solution is to count string in each char in "abc...z", and then, half of count will construct a new string.

For example, if the string counting: a2b2c2
then, the string A is one of strings {abc, bac, cba, bac, aca, cab}

Of course, "abc" is the smallest one in lexicographical order, but the possible string formats:
  abc***
  *abc**
  **abc*
  ***abc

Or, go through each possible string - find the minimum one, smart way to compare with previous one, keep the smallest one.

Assuming that the string is matching.

Got the idea. Linear solution.  From 8:19 am - 8:45 am, more than 20 minutes to come out the idea.

9:00 am -
Two functions - one function is to count the number to determine that count for each char is even. Another step is to go over the string, take substring(i, 3).

20 minutes to write a code, a bug to fix: wrong answer
Need to make sure that substring count matching count first, otherwise, skip it! 
  
9:15 am, bug is not fixed; and then, notice that the string has to be reversed! 

10:16 am, still not fixed. Julia, this is a greedy algorithm, why is the greedy part? You missed merge part in the construction merge(reverse(A), shuffle(A)). So, you have to redesign the algorithm.

Conclusion


1. Design algorithm - advanced - know why it is advanced, examine the idea and see if you can make it first; Otherwise, waste time to write code

Two hours, failed two tries! A new hacker is getting her valuable lesson using 2 hours.

Here is the C# code.

Follow up 


Blog review on May 3, 2017

Wednesday, March 30, 2016

HackerRank: String algorithm - Palindrome index

March 30, 2016

  HackerRank, Easy questions, 1 hours 3 questions. More practice, please! Get some momentum!

  Things are looking for:
  1. Tips to cut time to write code; 
  2. Make the problem a simple problem - read the hint ! 
  3. Avoid writing too many lines code in less than 10 minutes. 
  4. More tips !!!

  Problem statement:
https://www.hackerrank.com/challenges/palindrome-index


  Julia worked on this solution in 15 minutes, but she only scored 23 out of 25. She tried to figure out how to score 25. She missed the statement: "There will always be a valid solution."

  Her C# solution (Time out last test case): Time complexity O(N^2), N is the length of string

Julia's practice using C#, solution is here.
 

  So, Julia goes over those two cases in 25 minutes. It takes time to find great ideas:

  Solution 2:

use recursive function, while loop. Time complexity is O(N).

Solution 2


  Solution 3:

use iterative solution, once a possible index is found, stop. You do not need to verify that the string is palindrome. Assuming that there is a valid solution.  Time complexity is O(N).

solution 3


  Solution 4:

solution 4


Follow up after 12 months


April 26, 2017






Sunday, March 27, 2016

Video watching: a guide to object-oriented practice

March 27, 2016

Spent 2 hours to watch the video:

https://mva.microsoft.com/en-us/training-courses/a-guide-to-objectoriented-practices-14329?l=PLMOEi2hB_904668937

Take some notes, and also write down tips helpful.

Look up those terms:

internal
readonly
expression-bodied member
SRP - Single Responsibility Principle
S.O.L.I.D. - OO principles



Read some blogs:
http://stackoverflow.com/questions/28411335/expression-bodied-function-members-efficiency-and-performance-in-c-sharp-6-0

http://yqcmmd.com/2014/06/12/%E6%95%B0%E4%BD%8Ddp%E4%B8%93%E9%A2%98/



HackerRank: Sherlock And Anagram (VI)

March 27, 2016

 Julia was surprised to have a workout on this moderate difficult string problem from 9:00am - 4:00pm. She did some code study, and then, read so many codes from Microsoft, box, and saleforce, Amazon, and then, she read linkin profile, and blogs. She is getting connected to all other programmers in the world. HackerRank is young, all the coders are in charge of business this world, right now! No complaint.

 Just learn one good code  a time. Pay attention to some details. Follow up with a revisit once a while. Julia, you will make your programmer life easy, just relax, and see how people are creative to solve problems. You should do so, just copy the idea. Make sure that think by yourself first, do not be a copycat.

 This code is her favorite. She is still learning, never use SortedDictionary before,


 code reference:
https://www.hackerrank.com/Relentless

http://anothercasualcoder.blogspot.ca/#!

 Julia is too busy to work on coding, so she chooses on easy to moderate questions. She waited until 7 - 10 string questions, and then, finally, she worked on her first moderate question on HackerRank after 1 - 2 months. But, she likes to read other people's code, and then, she just needs ideas to solve problems.

 Here is the code gist:

https://gist.github.com/jianminchen/22f8e0de115cf656995e

/*
 Julia likes to talk about design of the function, through debugging, she knows a few things:

  For string "abba", 
  First, go over string with length 1, 
  then, SortedDictionary - key 'a', 'b', values are 2, 2
  then, Hashtable htPairs - key: a2, value: 

  then, go over string with length 2, 
  then, SortedDictionary - key 'a', value 1; key 'b', value '1'

  "abba" go through a loop, to get substring with length 2, in the order:
    ^  ->
     |
    "ab", 
    "bb", 
    "ba"
1.   string "ab", , key "a1b1",   htPairs["a1b1"] = 1
2.  string "bb", key "b2",          htPairs["b2"] = 1
3.  string "ba",            hashTable contains the key, so the value htPairs["a1b1] = 2
  Hashtable key "a1b1", sortedDictionary, value 2

*/
 static BigInteger UnorderedAnagrams(string str)
    {
        Hashtable htPairs = new Hashtable();

        for (int len = 1; len <= str.Length; len++)
        {
            for (int i = 0; i + len <= str.Length; i++)
            {
                SortedDictionary<char, int> anagram = new SortedDictionary<char, int>();
                for (int j = i; j < i + len; j++)
                {
                    if (anagram.ContainsKey(str[j]))
                    {
                        anagram[str[j]] = (int)anagram[str[j]] + 1;
                    }
                    else
                    {
                        anagram.Add(str[j], 1);
                    }
                }

                string finalKey = "";
                foreach (char key in anagram.Keys)
                {
                    finalKey += key.ToString() + ((int)anagram[key]).ToString();
                }

                if (!htPairs.ContainsKey(finalKey))
                {
                    htPairs.Add(finalKey, 1);
                }
                else
                {
                    htPairs[finalKey] = (int)htPairs[finalKey] + 1;
                }
            }
        }

        BigInteger finalResult = 0;
        foreach (string k in htPairs.Keys)
        {
            finalResult += Combinatorial((int)htPairs[k], 2);
        }

        return finalResult;
    }
Blogs:
http://juliachencoding.blogspot.ca/2016/03/hackerrank-string-sherlock-and-anagrams.html