Tuesday, May 16, 2017

Leetcode 582: Kill Process

May 16, 2017

Problem statement is here.

Introduction 


It is a binary tree data structure, and it needs to use BFS/ DFS search to find all children.


Problem solving 


C# practice is here.

Leetcode discussion link is here.  Learn to get involved in Leetcode community. Share the code first.

Study code is here. One more C# practice.

Watch Googler - Yu Zhou - Leetcode videos on youtube.com.

Will write down C# practice using Yu Zhou's idea in the the video - link is here.

C# code is here.

Actionable Item


Work on the algorithm Leetcode 480: sliding window median, the blog is here. Leetcode weekly contest 14.

Leetcode 581: Shortest unsorted continuous array

May 16, 2017

Introduction



Julia likes to be a good problem solver, one thing she starts to do in this May is to solve algorithm problems every day. If she solves 2 algorithm problems a day, then one month she can finish 60 of them.

One of ideas is to work on past over 32 Leetcode weekly contest, and try to solve weekly contest algorithms. Each contest has 4 algorithms, so there are over 100 algorithm.

Top performers can solve 4 algorithms in a hour, based on the lead board of Leetcode weekly contest. But Julia sets the target to solve first easy algorithm in half hour, and then second algorithm in medium level one hour.

Problem Solving 


Problem statement is here. The algorithm is easy level. The target is to solve it in 30 minutes.

It took more than 30 minutes to come out the sorting idea, and just compare to sorted array.

C# practice is here.

Leetcode discussion link is here.

Sunday, May 14, 2017

Testable JavaScript

May 14, 2017

Introduction


As a hackerrank contest player, Julia likes to do some research on how to improve her performance. She was surprised that she could not figure out easy algorithm on Hackerrank last year, and then she posted questions on codereview.stackexchange.com, and then she quickly followed the advice. She felt more confident on easy algorithm on hackerrank contest. Here is one of questions she asked on a easy algorithm called Spiral Message.

For medium level algorithm, Julia stumbled badly on Rookie3 maximum score algorithm. She tried to look up the lead board and then tried to find out a good solution to work on her skills, and then she figured out that it is better to work on the basics. She remembered that she read a book to teach how to set up a good test case, and she likes to enhance her skills to use test case for the algorithm analysis.

The book is called "The art of readable code", chapter 14: testing and readability.

It is always a good idea to read book written by google programmers, specially short books like 200 pages.


Testable JavaScript




It is a good idea to read the book called "Testable JavaScript" again in 2017.

Choose a good fight, instead of fighting against the hackerrank contest lead board, Julia likes to follow the author, Mark Ethan Trostler, a googler by reading the book again.

The ideal case is that Julia will design the algorithm using a new school technique, by working smart on testable idea. Really focus on a small unit test case, instead of focusing on recurrence formula, analysis of the algorithm. Will try to read the book again in 2017 and see if there are some valuable ideas in the book.


Show how hard Julia tries to study the book and gather all topics she should learn again.



Book reading 



May 14, 2017 3:20 pm - 4:29 pm
Read the book from page 1 - 13, page 35 / 273, chapter one.

Chapter 2. Complexity 


Code size


Notes:

comand query separation - commands are setters and queries are getters.

internal and external names of docRoot versus realRoot


A better solution is to use private properties with public getters and setters.

Try to read JavaScript code and understand the discussion - maybe I should put the code in html page next time.
Try to complete chapter 2 reading first.

JSLint



Cyclomatic Complexity 



independent paths

jsmeter - a command-line tool


Read the article about Complexity metrics - link is here.

multiple exits -


bad fix probability

Actionable Items



Elements of JavaScript style - article link is here. Chinese translated version is here.

12 books every JavaScript developer should read - article link is here.

Read the book "The art of readable code" again. First reading is in 2014, Oct. 31, 2014.
Chapter 8: Break down giant expression - favorite example:

 Two ranges does not overlap

Saturday, May 13, 2017

Graph or permutations with constraints?

May 13, 2017

Plan to read this algorithm called "Graph or permutations with constraints?". The coding blog link is here.

Friday, May 12, 2017

Maximum Score - Rookie 3 (II)

May 12, 2017

Introduction 


It is a good idea to continue to work on maximum score algorithm, and also ask a question on code review. Learning memoization and bit mask is not an easy task, also Julia likes to learn the time complexity analysis algorithm better through the study.

Julia wrote a blog to document her learning experience on the algorithm, from the contest performance to after-contest catching up.


Code review preparation 



C# code in the contest is here. Score 3.5 of 35 points. 

May 12, 2017 11:16 pm 

Code review of C# code in the contest, and then move the memoization out-of-for-loop, scored 10.50 of 35 points. C# code is here.


Memoization Analysis Challenge


Instead of going over the recurrence formula, Julia likes to use an example to explain what can be in memoization. And what is her mistake in the contest? What is the reason causing the false analysis?

Suppose that the array has two numbers, int[] numbers = new int[]{1, 2}. The problem is to find the maximum sum such that the order of two numbers to put into scoring make the value maximum.

What is the subproblem of max score?

Guess what is the subproblem


May 13, 2017 11:03pm

First, add sum of the array. The array new int[]{1, 2}'s sum is 3.

To choose the last number, two options, either 1 or 2. If the last number is 1, array's index is 0, then the 0th score is (3 - 1) % 1 = 0. Next number is 2, sum is 0, and then the 1th score is 0 % 2 = 0. The sum of score values (0th, 1th) is 0.

In other case, if the last number is 2, array's index is 1, then the score is (3 - 2) % 2 = 1. Next number is 1, sum is 0, and then 0 % 1 = 0. The sum of score values is 1.

From the above two cases, the maximum score is 1 by taking 2 as last number and then taking 1 as the first number. Just remind friendly that the order is opposite from end to start.

The maximum value is to choose maximum value from a set with two values.

The memoization process is to record to Dictionary<string, int> calculated.
["0", 1]
["1", 0]
["", 1]


One more test case 


Suppose that the array has two numbers, int[] numbers = new int[]{1, 2, 1}.

Calculated variable as Dictionary<string, int> has the following:
[0 1, 0]
[0 2, 0]
[0, 1]
[1 2, 0]
[1, 0]
[2, 1]
[,1]

Debug the code, and check how many times the dictionary is looked up. 3 times.
key = "0 1", "0 2", "1 2".

Draw a recursion tree for this simple test case. Here is the graph:

Argument: If you can work on this simple test case and also work out the recursion tree correctly, then I believe that you can solve the problem using memoization and recursive, DP solution correctly as well.


Common advice




Do not memo one more item in one recursive call; Stay outside the for loop; Memo before return statement.

Julia, if you are very good at unit testing, and work on simple and very good test case in the design of algorithm, your performance on Hackerrank can improve at least 20%.

Make it all


It is the first challenge Julia worked on since last January on hackerrank, on the topic of bit mask, dp, memoization, subset. So she likes to make the algorithm everything. Learn one algorithm a time. Do not rush.

Julia likes to review a list of things on the algorithm. Bit mask, memoization, time complexity analysis.

Use bit mask, the code passes all test cases. 
C# practice code is here.


Hackerrank Editorial Notes


In order to write a good question on code review, Julia also have to write down some notes from editorial notes from hackerrank on the maximum score algorithm.

Here is the link of editorial notes.

Julia's note:
time complexity: O(2n * n)

Recursion tree - a major flaw, same recursive call many times; It results in exponential running time.


Actionable Items


Read book "Testable JavaScript" and then figure out a few things I can do in order to have a good sense of setting up test cases to help Hackerrank contest.

The algorithm is also on code review.stackexchange.com, the link is here.


Algorithm drill

May 12, 2017

Introduction


It is better to discipline yourself as a software programmer. How to do that in busy schedule, specially in Saturday and Sunday? Julia likes to choose old Leetcode weekly contest or Hackerrank hour rank to practice, so she can spend 60 to 90 minutes to work on a few algorithms, she plans to have some practice this Saturday.

Ideas 


Put yourself constantly in the pressure, that is the way you grow. Make it a daily grind, 1 or 2 algorithm, if you are very talent, top 10% in the world, you should be able to solve 4 algorithms in one hour. Here is the leetcode week 32 contest ranking. 90 minutes, 4 algorithm, top 72 players score full score 26 in 90 minutes. 

Leetcode 575: Distribute Candies

May 12, 2017

Introduction


Distribute candies is the first algorithm in Leetcode Weekly Code 31, Julia likes to work on one algorithm today to calm down. She misses the fun to write an algorithm right now, 9:43 pm, so she
chose last Saturday weekly contest to practice.


Distribute Candies 


Time is checked. It is 10:19pm. The C# practice code is here

Thursday, May 11, 2017

Selected algorithms on GeeksforGeeks

May 11, 2017

Plan to read some algorithms on this blog - Aashish Barnwal.


Dynamic Programming and Bit Masking

May 11, 2017

Introduction


As a hackerrank contest player, Julia has hard time to manage her performance and expectation on Maximum Score algorithm. She failed to score on Maximum Score algorithm, only scored 3.5 out of 30, 10% or so.

It is better to learn a new topic called Dynamic Programming and Bit Masking. A good player should also be a good learner. Talk about failure is easy, but find a good topic to study and write down some good notes, it takes some determination.

Life is a little boring as a programmer if every contest on hackerrank comes so easy and score 50% up so easily. It is part of journey to excellence, every 10% experience counts a good practice.

Reading an article is never so enjoyable since Julia depends on the study; one day she will document one algorithm she easily scores full score, and tonight study makes her a good thinker in bit masking.

Bit masking, Julia likes to mask things using bit manipulation. It is not that hard, Julia taught Microprocessor lab a few times from 2001 to 2004, every time she had to learn again.

Dynamic Programming and Bit Masking 



 Hackerearth.com dynamic programming and bit masking, article link is here.

Fun with bits - topcoder article study

May 11, 2017

Introduction


It is so interesting experience to play rookie 3 contest. Julia spent a lot of days after the contest to play with one algorithm called Maximum score. She wrote a blog documented her experience, and then she likes to study a topic - use bits of an integer to represent a set. The topic is about a set, and also using bit manipulation.

Fun with bits


Top coder - fun with bits, the article link is here.

Take some notes:
Use bits of an integer to represent a set. Not only does it produce an order-of-magnitude improvement in both speed and size, it can often simplify code at the same time.

Go over the most popular set manipulations in the following:

Set union         
A | B

Set intersection
A & B

Set subtraction
A & ~B

Set negation
ALL_BITS ^ A

Set bit
A |= 1 << bit

Clear bit
A &= ~(1 << bit)

Test bit
(A & 1 << bit) != 0

Extracting every last bit

Counting out the bits

Tuesday, May 9, 2017

Bipartite graph small talk

Introduction


It is so enjoyable to learn a new algorithm every day. Also, it is also a good practice to write a small algorithm to solve a problem everyday.

Plan to read wiki article bipartite graph first, and then work on a geeksforgeeks algorithm.

The article link is here. And the geeksforgeeks.com article is "check a graph is bipartite".

Bipartite graph 


First C# practice code is here. There is a bug on line 55, 56, LinkedList RemoveFirst api should be called, otherwise the while loop will loop forever.

Second C# practice code is here. The test case in Main function is a loop with 4 nodes, so it is bipartite graph. Return true.


Add more test cases later.

Actionable Item



Read the moderator Aashish Barnwal of the geeksforgeeks.com

Read "How is it to be interviewed at Microsoft?" on quora. Link is here.

Geeks article about interview, link is here

interview cake - Julia's new school

May 9, 2017

Introduction


It is a wise decision to work on interview cake and learn how the website is designed to help programmers improve technical strength. Julia knew the website starting from February 2017.

Today, Julia read weekly email from interview cake and then spent 10 minutes to go over this link - Word Cloud Data.

Study 

Monday, May 8, 2017

Catalan number wiki article

May 8, 2017

Introduction


It is very interesting to study catalan number again. This time Julia likes to go over the wiki article and then try to get better understanding the algorithm.

Tonight she had mocking experience to learn an algorithm - find maximum number of path from bottom-left corner to top-right corner, and do not cross the diagonal line. In other words, always stay underneath the diagonal line. She learned that the algorithm is similar to Catalan number.

Catalan number 



Sunday, May 7, 2017

Recursive function design talk

May 7, 2017

Introduction


It is the 21th mocking experience this Sunday evening. Julia thought about writing about a blog about 21 mocking experience, what she has learned so far. And then she talked to herself it is better to do one thing at a time. Just talk about one mocking experience a time.

It is the middle of year, May. Julia likes to get started to work on some website project, study some pluralsight.com courses, and then practice some website technology.


Recursive function design talk 


Transcript is here

A few issues need to be addressed.
1. cheapestCost in the function name is not accurate, it should be minimalCost.
2. I should ask a lot of questions when designing the function, do I need to store all the paths? Do I need to keep track of each value on the path? Do I need only the value from the root node to the current node? Need to clarify the question.
3. The recursive function can be designed in different wasy, right now Julia chooses to use "ref minimalCost" in the function argument, but people may not have the idea to solve the algorithm.
What is the alternative way to write?

Actionable Items


Read something interesting:

Read one of article - link is here.

International Olympiad Informatics - wiki article is here

Culture Conference - Rookie 3 contest

May 7, 2017

Problem statement: Culture Conference

Introduction


It is very interesting contest experience. Julia did not write a lot of code in Rookie contest, first she decided to review Union find algorithm, studied one of C# solution first. But in less than one hour, she used the algorithm to score a full score 20 on a medium algorithm - Maximum tourism. And then she started to work on the hard algorithm called Culture conference with maximum score 55. Julia also did not have time to write code, she was busy with tennis sport 2 hours, and one hour mocking interview around 8 pm. So she decided to use same algorithm Union Find to calculate the minimum number to attend the conference, a minimum dominating set, she scored 3.5 and then made some improvement to score 5.5.

One algorithm Union find helped her to score more than 30 point on two algorithms in the contest.

Here is her submission report on the algorithm.


Code review 


C# code is here.

The function Julia worked on in the contest from line 248 to 269 is here. She tried to adjust the maximum saved people by thinking about one node with more than one child, how many can be saved to let the parent node to go to culture conference, that is children.Count - 1.

Code snippet is here:

Follow up 


May 5, 2017

After the contest, study code written in Cpp file. Code is here.
Review code and then write a C# code. Code is here.

Performance Talk - 5 points to 55 points

10:37pm May 5/2017

Performance on this algorithm is based on the points I got. I got 5 points,  5 / 55 points, it is almost 10%. It is the hard algorithm, but the solution is not that hard to figure out.

Julia has to look into the performance issue in the contest Rookie 3, and then write down some tips to improve. Simple and practical tips.

May 9, 2017

Download test case 2, and then test the C# code in the contest using test case 2, and then modified the code. It took hours to fix the issues related to union find algorithm. Code is here, still need more work. Union Find algorithm implemented only keeps every node's parent node to the disjoint set's root node. Its director supervisor is replaced with the root node. No way to get the correct answer.

May 10, 2017
Leave union find algorithm alone, add some data structure to check each node with subordinates and supervisor, similar to the study code. Therefore the algorithm can only handle those edges with burnout node with its parent, and also figure out how many people go to conference.

It is a good practice to add something to Union Find algorithm, therefore learn to solve a problem and also get chance to know more about Union Find algorithm.


Actionable Items:



Study lead board of Rookie3

Read the math Ph.D. student - a good programming on Rookie 3 - Kevin Vissuet is the profile. Resume is here to take a look.

Aaron Albin - Amazon employee

Rookie 3 on Hackerrank

May 7, 2017

Introduction


It is great morning of the Sunday, Julia woke up around 7 am and she decided to get up at 8:00 am and worked another hour for Rookie3 since the contest ends at 9 am PST. Last night she was so tired 10 minutes before 12 am, she knew that she had to go to sleep, stopped to work on Rookie3 algorithm called Culture Difference. She made 5.5 points out of 55.

Julia tried to get smart on the contest, she went out for a tennis sports around 1:00 pm last Saturday, and then come back to work on the contest around 5 pm. And then she took one hour break from 8:00 pm - 9:00 pm, and came back to work on after 9:00 pm - 12:00 pm. She learned to take more breaks and also took care of contest activities.


She could not believe that she stumbled on the algorithm Max Score and could not score more than 3.5 out 30. She just reminded herself to keep learning recursive if that is only thing she could figure out to solve the problem.

Contest review 



Here is the contest progress report at 8:53 am May 7, 2017, 7 minutes before the end. 


Culture Conference Algorithm


It is a long journey from 59.00 points to 140 points. Learn one theory behind the algorithm in the contest a time, now it is a domination set show time.

Julia did not know one of the algorithms is using minimum dominating set based on the editorial note. The dominating set was such a hot topic back to her Ph.D. study, but she never had a chance to write any graph algorithm to practice by herself. Here is the journal paper written by professor Jie Wu and Fei Dai. This is a better link to read the paper quickly.

Julia went to bed still thinking about the algorithm "Culture Conference" around 12:00 am, and woke up around 7 am and still thought about ideas to try to gain a few more points on the algorithm.

This is a really testimony of good relationship between hackerrank contest and academic research. But Julia did not know what she tried to work on is a dominating set, she tried to google but had no good keyword to search in the contest. She took a few graduate courses on network protocols in her Ph.D. study from professor Jie Wu back to year 2001, but she did not have the chance to practice one algorithm by her own. This contest made her Ph.D. study complete!



Saturday, May 6, 2017

Max Score - RookieRank 3

May 6, 2017


Plan to work on the algorithm: Max Score in next 1 - 2 hours. Time is 5/6/2017, 12:53 pm.

Follow up 


May 7, 2017 9:20am

C# code in the contest is here, scored 3.5 out of 35.

Follow up 


Study the discussion about the solution, the link is here.

1. The following implementation uses memoization, backtracking, and backward processing:

C# practice code is here which passes all test cases.

2. Continue to work on my code submission, change the key of memoization, relax to the sum instead of the string concatenated by various array's element.
Score 14 out of 30, timeout test cases 7 - 10.
C# practice code is here.

3. Bit mask - pass all test cases
C# practice code is here.

Bit manipulation 4 things to review

1. Get integer 2i:
//use left shift i times,
bitToCheck = 1 <<  i

2. Check ith bit is 1:
// int bitmask
bitmask & bitToCheck

3. Get ith bit:
bitmask |= bitToCheck,

4. Unmask the ith bit:
// backtracking
bitmask &= ~bitToCheck


4. Bit mask - replace the integer using int[], size of array is 20.
May 11, 2017
Timeout on test cases from 6 to 10. Score 10.50 out of 30.
C# practice code is here.
string.Join(",", bitmask) takes too much time.

Julia learned the lesson. Take some time to write bit manipulation instead of using int[]. Bit manipulation expedites the process, use int instead of int[].

5. Continued to work on code written in the contest,
May 12, 2017 11:11 pm
C# practice code is here. Score 10.50, pass test case 0 - 5, and timeout on test case 6 - 10.

Learn when to do memorization, it should be out-of-for-loop, memo on the used HashSet<int>, actually encode all used indexes of the array to a string. Move the memoization from inside for-loop to outside for-loop.

Algorithm analysis


It is most important to come out the recurrence formula for the algorithm. Try to work backwards instead of starting from the first number and forward.

The maximum score of k problem can be solved by choosing any number as the last kth number, and then work on the maximum score of - 1 problem. Use bitmask as key to do memoization.


Actionable Items


Review previous practice, and find some cases to use bitmask.

Top coder - fun with bits, the article link is here.

Take some notes:
Use bits of an integer to represent a set. Not only does it produce an order-of-magnitude improvement in both speed and size, it can often simplify code at the same time.

Go over the most popular set manipulations in the following:

Set union        
A | B

Set intersection
A & B

Set subtraction
A & ~B

Set negation
ALL_BITS ^ A

Set bit
A |= 1 << bit

Clear bit
A &= ~(1 << bit)

Test bit
(A & 1 << bit) != 0

Extracting every last bit

Counting out the bits

2. Hackerearth.com dynamic programming and bit masking, article link is here.

Friday, May 5, 2017

Union Find Algorithm - one hour workout

May 5, 2017

Introduction


It is a good idea to have my own union find C# class and also put some test cases together for future use.

Here is the article to talk about union find in details on hackerearth.com.

Here is the blog to document the study on the topic.

Here is the blog to document more than one hour study on union find algorithm in world codesprint 10 contest.

Union Find Coding


It is in incognito mode, Julia did not share any code because she played the Rookie3 contest.

Follow up 



May 7, 2017 9:27am

Julia spent hours to test the union find algorithm, and planned to apply the algorithm to solve one of Rookie3 contest algorithms. She just applied the test case in less than one hour and solved the algorithm on Rookie3, score 25 point very easily. She did not have chance to look into the detail of the algorithm. 

May 10, 2017

Code review C# solution, and C# code is here

The path compression is implemented in the above algorithm. Every node's parent node is set to the root node of tree.



Maximal tourism - rookieRank 3

May 5, 2017

Introduction


Problem statement is here. Plan to work on the problem.

Code study 


Follow up 

May 7, 2017 9:22 am

Code submission in the contest is here. Score fulls score. 

Julia did not write any code, she reviewed union find algorithm and tried to get some experience of union find C# code, she just used the algorithm to test her union find code as the second test case.


Thursday, May 4, 2017

Algorithm learning small talk

May 4, 2017

Introduction


It is very interesting to read the article called "when pressure and off-court life overcome talent and results". The article link is here.

It is more exciting to practice coding and attend contest in the weekends. Julia enjoys the contest and also likes to push herself to join the community and share what she can do. Here is the blog to show her ask code review on a hard level algorithm in Hackerrank world codesprint 10 recently.

Julia had a mocking experience tonight, she had a big surprise about learning a dynamic programming algorithm.

The problem is a very ordinary solution using dynamic programming, recursive solution.

The deletion distance of two strings is the minimum number of characters you need to delete in the two strings in order to get the same string. For instance, the deletion distance between "meat" and "mit" is 3:
  • By deleting 'e' and 'a' in "meat", and 'i' in "mit", we get the string "mt" in both cases.
  • We cannot get the same string from both strings by deleting 2 letters or fewer.

Less means more 


How to analyse the above algorithm? 

Use frog and dog as an example, we have two words, we like to linear scan two strings from left to right, all starts from the beginning. First chars of two strings are 'f' and 'd'. If they are equal, then both pointers go to next one. Otherwise, we have to move one of pointers. Both cases should be counted. In other words, 'd' is deleted, then continue to work on two strings: "og" and "frog"; or 'f' is deleted, then continue to work on two string: "dog" and "rog". 

So far, the analysis is perfect. We cannot sort the string, because the order is important and has to be kept. The count of char does not help much. The brute force solution is not good since it will be O(n2), actually it is hard to find a brute force solution.

In other words, recursive function can be written in the following recurrence formula:

CalculateDeletionDistance(s1, s2) = CalculateDeletionDistance(s1.substring(1, length1 - 1), s2.substring(1, length2 - 1)) if s1[0] == s2[0];

Make it short, CalculateDeletionDistance is shorted as CDD, s11 is the substring of s1, s21 is the substring of s2.

CDD(s1, s2) = CDD(s11, s21) if s1[0] == s2[0],
CDD(s1, s2) = 1 + Math.Min(CDD(s1, s21), CDD(s11, s2)) if s1[0] != s2[0]

Basically the recursive function is depth first search, base case should be calculated the deletion distance. And then in order to save time, it is better using bottom-up solution, called dynamic programming method.

Edit Distance Algorithm


Previous practice on Leetcode 72 is here. Spend 20 minutes to review lecture note from standford again. Also plan to spend 30 minutes to review Leetcode discussion, link is here.

Julia was wondering if the dynamic programming is also solvable using DFS algorithm.

Actionable Items


Plan to read the article on topcoder: Dynamic Programming - From novice to expert, the link is here.

Read the facebook engineering manager - Yi Huang's linkedin profile.

Take some notes from the recommendation:

Understand to build a hobby - writing code, solve problems on topcoders:

"Numerous times we turn to each other to discuss algorithm and optimization problems and every time I am impressed how insightful Yi can be. Yi has won countless programming awards and takes coding as a serious hobby. Yi has great enthusiasm in algorithm optimization. His hobby is to log into topcoder and attack one problem after another. He also has the great ability to apply research knowledge to actual programming. He is one of the few guys that will always think of how to turn research results into reality."



Wednesday, May 3, 2017

Communication drills

May 3, 2017

Introduction


It is very interesting to work on communication skills. Julia started to follow tennis professional player interviews, Julia likes Sharapova's perfect English, but she also started to like players with French accent, Spanish and German's accent.

One thing Julia likes to learn is to get more ideas about thinking process of professional tennis players. Every player uses those terms about controllable, mental game, and shares their mind and problem solving process through tough matches.

Communication drills


Her most favorite talk on May 3, 2017 is here.

Djokvic

Defending champion Djokvic Seeking Freshing Start in Madrid 2017. 5 minutes video is here.

Notes: changing coaching team, love tennis sports, competition or practice.
Mental? Ten years behind me, so much success, gain a lot of experience. Use those experience for practice, future matches, confidence is tricky thing, long time to build it, quick to lose it. You have doubt, and you have to deal with it. How to approach that? Not change a lot.

Ambitious person, go back to basics, analyze the game, believe the result will follow.

ATP world Tour Stars React to Djokovic Coaching Decision - link is here. 3 minutes video

Mladenovic

Mladenovic Press Conference After Match vs Sharapova - Stuttgart 2017, 13 minutes video.


Siegemund

Siegemund Press Conference After Final vs Mladenovic - Stuttgart 2017, 5 minutes video.


Julia saw Siegemund practice in China Open, Beijing 2016 October. She knew that the professional player was so focus in the practice court, and also very sociable with fans after the practice.

Take notes:
Find ways to solve the problem, think small units to do.


Maximum Disjoint Subtree Product - World codesprint 10 (II)

May 3, 2017

Introduction


The algorithm is one of hard level in the hackerrank world codesprint 10. Julia put together a C# code after she chose to study one of C# submissions in the contest. She likes to ask code review on stackexchange.com.

The algorithm is a depth first search algorithm, after over a few hours study, the algorithm becomes easy to understand.

Here is the C# code almost ready for code review.


Code review 


Code review link is here.

Monday, May 1, 2017

Facebook product engineers

May 1, 2017


Watch the 30 minute video, product engineers from Safety Check, News Feed, and Videos. The link is here.

Array patches

May 1, 2017

Plan to study the algorithm called array patches. It is written in Chinese. Will find the similar algorithm written in English. The link is here.

Problem statement: Given an ascending sorted integer array nums and an integer n, add a few of elements so that any number in the range of [1,n] can be expressed as the sum of a few elements in the array, ask for minimum elements to add into the array.



Facebook - reflecting on 2016 and looking forward to the new year

May 1, 2017

Introduction


It is such a good video to watch, Julia watched two times. Each takes 16 minutes. The link is here.

It feels so good to spend one hour to study Facebook as a company, and Julia had to learn new things Facebook are developing today.

Video study 


Take some notes here.

Sunday, April 30, 2017

Talent small talk

April 30, 2017

Introduction 


It is a very happy weekend with a world codesprint contest and then two mocking experience. Julia also spent one hour to play some tennis and felt much better after she ran 30 - 45 minutes, she was amazed that her muscle memory of tennis was so good, she could control tennis balls so well through a full court rally. She enjoyed the sliced shot and very good timing and control of landing position to hit a stroke.

She also felt that it is important to seek the advice to be a just-so-so contest player scoring 36 points over 13 hours compared to top players scoring more than 280 in less than 2 hours. Read those data - less than one hours 10 minutes, top number 1 - Gennady.




What are the missing parts she should work on next?

A lot of professional WTA tennis players are very good at changing coaches when they deal with up-and-downs. What does Julia do for this case? Should she change her coach? She is self-coaching and writing blogs to keep tracking of her progress.

Need a therapy after the contest. Remember the favorite video she watched about Roger Federal talking about his early age, throwing tennis racquet in front of thousands fans. Take some time to learn from Roger Federer.

Watch this video to get entertained. Roger Federer - top 10 smiling after points lost, link is here.

Talent talk 


Where is the talent? I like to find some drills to work on to help myself to cover the weakness of talent. 

Watch the video - tennis funniest moments ever. Link is here. And read the article - waste time is healthy in big data term, link is here

Data structure talk 



Julia met a same person for the second time in less than 30 days through mocking experience, and then she learned a few things through 30 minutes. Friendship forms quickly after the first experience.

Case 1: She likes to design a data structure to return a list of pair integer numbers in the array, she said that since it is the unknown size, she likes to declare C# IList<string>, and then "why it is string?" The peer asked, Julia said that because there are two numbers, I like to encode and decode like a + b; otherwise I like to use Tuple<int, int>, the peer just typed that you just use this one IList<int[]>.

Julia never uses this one before, but it is so good ride once she uses it. Story is short, better give a good name "int[] beats string".

Case 2: Julia likes to change HashSet to a Dictionary<int, Object>, and then the peer asked, can you make a minor change to fit the requirement; Julia was told to finish the coding, and do a whiteboard testing using a test case. Do mocking algorithm really need Dictionary that complicated?

Through the discussion, Julia learned that it is a good practice to write simple code. Be more organized!

Transcript is here. Later it will be compiled to C# code.

Recurrence formula talk 



It comes out that the recurrence formula is challenging for those 3  talented programmers in the world last weekend. In other words, Julia used the same algorithm to interview two people last weekend.

Her first interviewee was troubled, confused, since the problem statement is wrong, and Julia had difficult time to step in and give good hints to guide, since Julia had a math degree but it is like the muscle to fat story, she also got confused on recurrence formula in those 30 minutes. But then second time to use the algorithm, Julia was more determined to apply recurrence formula, no more playing with test cases. Just write down clearly the formula first.

The interviewee is much quickly to take hint, and then write code. She felt those two difference. Less experienced one is much more easy to try new things.


Also Julia learned the algorithm quickly, when she interviewed second person using same algorithm, she wants to make the difference. She learned that good interviewer should do something to help out. 

Whiteboard technique



From the contest to the leaderboard by Microsoft to a blog writer -

Google intern and interview blog is here. Whiteboard talk is excellent.

Bronze medal talk



It is the time to celebrate Julia’s fifth bronze medal, Julia got a bronze medal for world codesprint 10. How to express the feeling of bronze medal? Julia likes the hard work she put in those hours, and she did so much work and tried again and again for new ideas to break through the hurdles. She is more experienced to play contests now compared to last year.

Julia takes time to enjoy her status right now, one day she will easily make over 30% or over 100 points and come back to look at the stage she is in. Honestly the contest is like school home work, and bronze medal is for Julia to celebrate a grade “C”, but she tries to get grade B – silver medal, one day she can get grade A. Julia scored 36 point (360 maximum points), 10% scoring. 


Julia likes the competition because it is fair, open and her peers are all over the world. Compared to take algorithm course in university to learn more, she does not need to figure out who is the professor in the university, fair or not fair on grading. All she has to do in the competition is to work damn hard, write down something, either a blog, or code or analysis. Dedicate a few hours on each algorithm in the contest. From there she can continue to work on after the contest. 

Psalm 126:5 Those who sow with tears will reap with songs of joy.
6 Those who go out weeping, carrying seed to sow, will return with songs of joy, carrying sheaves with them.

Julia sowed, teared, reaped, sung, weeped, carried.

Follow up on data structure talk 


In previous data structure talk, Julia shared the story about mocking experience. The peer coached her to use int[] instead of using string or Tuple<int, int>. Such a wonderful coaching through mocking experience.

Afterwards, Julia asked her favorite algorithm coach JS1 on code review about using int[] data type compared to string related to Queue. Here is the algorithm question on code review. 

do you think that it is also good idea to declare var queue = new queue<int[]>? row and col can put into the array new int[2]. Therefore, we do not need to encode a key and then decode the key to row and col two variables. I am learning data structure and try to speed up coding. – Jianmin Chen

It's a matter of preference. I tend to use primitive types whenever possible, but if using int[] seems easier to understand than using a single int, then you should do that. Note that using a single encoded int leads to a simpler visited array as well. – JS1 

Hackerrank world codesprint #10 contest performance small talk

April 30, 2017

Introduction


It is a good decision to review the contest practice, from several perspectives, hours spent, breaks taken, and things to work on in order to improve performance.

Contest Review 


First of all, do not sit in the home office more than 13 hours, no breaks. It is not healthy, and do not worship the contest result. It is just a tool to help training the great thinking in algorithm problem solving.

Also, it is a very good intense practice to write a few algorithms in a day in the contest. The whole week was gone without writing some algorithms until this world codesprint contest.


Saturday, April 29, 2017

Node-point mappings - world codesprint #10

April 29, 2017

Introduction


It is a good idea to do some research about the algorithm, how difficult it is. Julia just did a quick research and then found out this algorithm - Node-point mappings is not an easy one. Players like ICPC winners may not score full points, only partial of them.

Through the study and research about the algorithm, Julia noticed that it takes a lot of efforts to master the algorithm in advanced level.

Here is the comparison with one of top players. Julia noticed that it takes a lot of work probably years, thousands hours to be able to perform like the other one.

And Julia reviewed the player past performance:

  • 1st at USC Programming Contest
  •  
  • Gold Medal at the 2014 ACM-ICPC Asia Regional Contest, Shanghai
  •  
  • Gold Medal (the 4th place) at the 2014 ACM-ICPC Asia Regional Contest, Beijing
  •   
  • 19th place at the 2014 ACM-ICPC World Finals, Ekaterinburg
  •  
  • Gold Medal (the 4th place) at the 2013 ACM-ICPC Asia Regional Contest, Changsha
Profile is here.

It is not easy to learn by yourself and catch up the performance. Best bet is to go back to the third and fourth algorithm and try to score any point in the fourth algorithm.


Code study


Problem statement is here.

Follow up after the contest 


4/30/2017 1:17pm
.


Maximum Disjoint Subtree Product - World codesprint 10

April 29, 2017

Introduction


It is a wise decision to spend time for each algorithm in the contest. Even Julia did not make any points last few hours, she found out that it is better to write a brute force solution even scoring 0, or write a blog about the algorithm.

The maximum disjoint subtree product algorithm should be a DFS/ BFS tree problem. Julia had some idea to solve the problem, but she was not sure how simple the code should be.

The problem statement is here. Just work on the most simple test case, and then write some code first.

Plan to do 60 minutes workout on the algorithm. 3:03pm - 4:03pm.

Code preparation 


Read one of players resume, and go over all the players in united states scoring 60 on the algorithm. 3:13 pm, study those players and get myself ready to think about a solution and start to write down some code. 

4:00pm now - spent 20 minutes to go over those 24 people scoring 60 maximum points, and I knew that those are very experienced ones, Julia spent time to loo at those who scored 3 points, 6 points, to 30 points. Those are players who are working hard as well.

Go back to study on topcoder webpage after googling disjoint set, make the algorithm general. How to approach? Article is here

Finished 15 minutes to read the disjoint set article first. Time is checked, 4:15pm.

Disjoint-set Data structure - topcoder tutorial


Read the article - link is here, and take some notes. 

Disjoint sets, dynamic disjoint sets,
Define two sets are disjoint - intersection is null
representative - Every disjoint set contains a representative

It is assumed that the representative of each group is the person with the biggest index in the article.
Every one has its own group
-> the group containing 1 and the group with 2 will become one group.
-> the representative of first group will become 2.

How to check if two persons are in the same group? Check the representative.

Define some operations:
Create-Set
Merge-Set
Find-set

Implementation with linked lists

Each element will be in a linked list and will contain to the next element in the set and another point to the representative of the set.

Read the graph representing the problem, catch up more later.

Read how to implement the Merge-Set(x,y) operations.

a weighted-union heuristic - complexity O(M + NlogN)
where M is the number of operations (Find-sets, Merge-sets, Create-sets), N is the number of operations Create-Sets.

Two heuristics -

Union by rank
Path compression

Time is checked again, 4:53pm.

Move on to next topic

Disjoint Set questions on Hackerrank


Link is here.

Disjoint Set tutorial on hackerearth 


The article link is here.

Being a hacker 


Wrote a brute force solution to work out on sample test case, but the code passed test case 1, failed 2, 3, and time out everywhere. Score 0. Time checked, 10:53pm.



Can hackerrank give me 0.001 points? I just need 0.0001 points.

Is that possible to give 0.25 points for passing test case 1? I wrote a brute force solution just to try to advance my ranking. My points are 36 points, ranking from 767 - 1307 all scoring 36 points. Never work so hard to advance 0.25 point, failed this time.
Here is the comment link. 


Follow up 



Code written in the contest is here

Study one of C# submission code. C# study code is here with sample test case. 
Continue to code review the algorithm, prepare to give a code review on stackexchange.com, here is the C# code. 

Permutation Happiness - hackerrank world codesprint #10

April 29, 2017

Introduction


Problem statement is here.

The algorithm is very interesting. Julia has to find one of algorithms to work on and make some points. Start from one extra point first, now is 4/29/2017 12:50pm.

Julia wrote a brute force solution and sample test case of  "7 people are happy out of 10" is timeout. At least Julia started to write the code and understand the problem now. It is 2:04 pm, almost 60 minutes later.

One of ideas to solve timeout is to use dynamic programming. Need to figure out the recurrence formula next step.

In general, we only need to make sure that at most n - k are not happy, but we do not too much detail.


Coding in the contest 


Follow up


After the contest, Julia published her code using recursive solution. Link is here. Score is 0, timeout all the test cases. But it is a great workout for recursive solution. 

Julia did think about the dynamic programming in the contest, she tried to build recurrence formula. She almost had the same idea showed in the editorial notes. But she did not write down the detail. 

It is a good idea to write down the dynamic programming thinking process, and post the algorithm on the code review later on. It is not hard, for a mathematics major, all Julia has to do is to start to practice again the mathematics analysis. She will figure out what to do next after the contest, how to train herself better. 


Maximal AND Subsequences - hackerrank world codesprint #10

April 29, 2017

Introduction


Problem statement is here.

It is the medium level algorithm, but Julia worked over 7 hours and she only managed to score 6 points out of 30 points. She tried a few time, scored from 3 point to 6 points. She was so hardworking and put together the test cases, and also make sure that her code is readable, function name and variable name are meaningful. She is waiting for inspiration to break through, still waiting...

Julia spent time to write a binary search algorithm, and she enjoyed the function to help her gain 6 points. What else she can do? World codesprint #10 is so tough, she now knows that people are so talent in the world. More than 5 players finished all seven algorithm in less than 2 hours, and the first 3 winners are finalized with $2000, $1500, $750 prize money.

It is very exciting contest and also it is most competitive contest compared to week code or others.

Show some progress and cheer up.


Here is the comparison Julia chose to compare with a Google employee.


Coding in contest 


Two test cases time out and also near 10 test cases wrong answers. Need to read the discussion board.

Follow up 

4/30/2017 9:36pm

After the contest, Julia published her code in the contest, link is here.

Need to download test case 6 and figure out why the code fails test case 6. In theory, the algorithm is exactly the same showing in editorial notes.

5/1 2017
Code after the contest - replace recursive binary search with an iterative one, pass test case 22, 23, score from 6 up to 7.14. 

Code is here

5/3/2017
Read code submission the_watcher and lewin, learn to write using bit manipulation. 

Thursday, April 27, 2017

Count of Smaller Numbers After Self

April 27, 2017

Plan to study the segment tree algorithm - count of smaller numbers after all.

Plan to read the blog about the algorithm. The link is here.


segment tree

April 27, 2017

Plan to spend 30 minutes a time to learn segment tree from the Chinese blog.

Box Operations - World Codesprint #9

April 27, 2017

Introduction


It is Julia's favorite algorithm - segment tree. Past practice related are here. The first one is the algorithm Kindergarten adventure Julia asked the algorithm on code review website. The another one is the Chinese blog related to segment tree.

Code study 


Problem statement Box Operations is here.

Expert difficulty, time complexity O(n*logn*logC), required knowledge: segment tree.

Plan to work on the algorithm 30 minutes a time. Document the progress.




The optimal polygon (Approximate) - World codesprint #9

April 27, 2017

Introduction


It is always good to train very hard on expert level algorithm, and then it is much easy to work on algorithms in daily work or being on trial to pass the important test.

This algorithm is called the optimal polygon, the problem statement is here.

Code study 


Plan to spend 30 minutes first to read the problem statement and also think about the solution. Log every 30 minutes spent on this algorithm, and document the progress to learn and breakthrough the hurdles one by one.

Will come back to work on first 30 minutes very soon.

Two subarrays - World codesprint 9

April 27, 2017

Introduction

It is a wise decision to learn one expert level algorithm using dynamic programming and also RMQ algorithm.

The problem statement "Two Subarrays" is here. Maximum score is 70.

Code study 

Plan to spend 30 minutes to study the algorithm.

Toll Cost Digits - World CodeSprint 9

April 27, 2017

Introduction

Problem statement is here.

Hard problem, time complexity O(N+E), required knowledge: graph, BFS/ DFS.

Plan to work on the algorithm 30 minutes a time.

Kingdom Division - World codesprint 9

April 27, 2017

Introduction


The world codesprint is different from weekly code challenge on Hackerrank. The algorithms are more challenging and general, each world codesprint is also supported by some companies. Every 3 months there is one world codesprint on hackerrank. It is very wise idea to look into those algorithms and learn some new algorithms.

The problem statement kingdom division is here.

Code study 


Ideas to learn the algorithm after the contest can be anything like reading some submissions, general study of the topic. 

Plan to spend 30 minutes to work on the algorithm. Will come back very soon.