Friday, May 12, 2017

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 k - 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. 

Tuesday, April 25, 2017

Coding blog small talk

April 25, 2017

Introduction


Coding blog is part of my daily routine and then Julia also tries to learn something daily. Today I chose to study Sharapova through her tennis interview. Here are the interviews I went through and I liked the candid talk about sports, competition, design talk and business training etc.

Right now, Sharapova will come back to tennis sport this April using wildcard of tournament because she lost her ranking last 15 months. It is tough for her to come back like that, I also learns from Sharapova. It is amazing that Sharapova can express herself so well using English, amazed that she does not have time to go to college, but her intelligence and logic thinking is so well.

Maria Sharapova Opens up About Doping Suspension, Appeal, Return to tennis - Today video is here.
Maria Sharapova on training and preparing for WTA Tour comeback - link is here.
Sharapova's return - link is here.
Larray King - Maria Sharpova on locker room friendship - link is here.
Larry King - Serena is An Incredible Athelet - link is here.
2012 Alex Zolbert - Maria Sharapova's CNN talk Asia interview Part I - link is here. 7 minutes 38 seconds

2013 - Brisbane international 2013 - link is here.

Note:
I - Julia, the blogger write usually like to write using she instead of I.
She - sharapova

Coding blog small talk 


Big thanks to Google to provide Blogger such wonderful product, Julia enjoys the work daily to write down everything, and then she can rely on the Blogger, help her to share what her work and also provide a plaform for her to push herself to work hard and concentrate more on the coding. 

Julia was so surprised but she found a fact that top tier companies young programmers most of them can really perform high level coding skills, in terms of Hackerrank algorithm level, hacerrank.com, yelp.com, Alibaba.com, Google, Microsoft, all those player score high than Julia. Julia only performs top performer 30% and it takes her more time to reach the 30%, estimated 50% more time.

It took a four years until 2015 Julia decided to open herself and then shifted her focus on a most simple thing - coding, write down algorithm, show the naive, baby step to the world. She looked back the blogs she wrote in early 2015 and code she wrote early in 2015, the tough algorithm she felt and troubled over a week in 2015, now it was so natural for her to come cross the similar algorithm very often through her routine contest, weekly practice, mocking practices etc.

Another fact is that a lot of people work so hard to advance their coding skills, algorithm problem solving, but julia also likes to work on her writing skills in the same time.

Julia also found out that she learned better from tennis tournament - WTA, ATP events, professional tennis players. She spent over five hundred of hours to play tennis from 2012 to 2015, she got the experience how she gained the skills through hundreds of double matches, single matches, she played those 3 years tennis more than over 14 years in total in Florida, hundred time more, she played with over hundreds of hitting partners. She first experienced that tennis sports is her personal sports, she enjoys the sports and understands the hard work.

All she likes to do is to transfer last 3 years intense practise experience of tennis to coding. Coding can be tremendously improved by going through contest, competitive programming, all she has to do is to practice more, using Blogger to help her to manage the journey, get the data and analyse them.







Monday, April 24, 2017

Hackerrank leaderboard study

April 24, 2017

Introduction


After over 10 times mocking practice in April 2017, Julia finally felt much better to understand the algorithm problem solving and what she should do in her best interest. She understood that her mocking experience is related to the performance on her contest experience on Hackerrank. Right now she is still struggling to solve medium, hard and advanced algorithms on Hackerrank, performance of hard algorithm is from 15% to 30% of those algorithm.


To set a goal to get her first golden medal on Hackerrank contest, Julia likes to make a plan what she can do to help herself.

One idea is to review Hackerrank algorithm leaderboard. Julia did find something to study and then she read that people solve over 3000 algorithm problems and then usually can get good performance.

Leaderboard study - algorithm


Study the leaderboard. Link is here.
Bohdan hackerrank profile is here.

Plan to spend one hour a time to read quora - Bohdan Pryshchenko.

Is competitive programming helpful? Quora question is here.

Julia thought about this question. She made new friends through hackerrank contests, and also she got a few people to ask to connect through linkedin since they read my blog this month. And also Julia had good time to get help from stackexchange.com code review for those hackerrank algorithms. Most of important is that Julia started to review code she wrote before, and then she quickly comes out new ideas to improve.

Thinking techniques



From reading "Is competitive programming helpful?", a Quora question, Julia had chance to read another player's answer from the SFU computer science Ph.D., Mstafa Saad, and she read the article talking about thinking techniques.

Training style - discipline monitoring


SFU computer science Ph.D., Matafa Saad - article is here.

Actionable Items


Study shanghai business - https://www.dianrong.com/

Sunday, April 23, 2017

Visiting Manhattan - Booking woman in tech

April 23, 2017

Introduction


Timeout is the big challenge for the algorithm - visiting Manhattan.


Code review 


C# submission is here. Score 7 from 40 points.

Minimum Heap - C# practice

April 23, 2017

Introduction



A minimum heap C# code is needed for the Email everywhere algorithm in a booking woman in tech contest, so Julia googled and found the C# code. She put together with the algorithm and then she scored 30 points with a full score. Learning to use heap is a great mark for Julia, she knows that completely sorting is expensive, if only max and min value is needed, better to use binary tree, not binary search tree. Julia starts to learn using heap when she work on algorithm problem solving.


Code review 



C# code is here. Need to add some test case and do some code review.

EmailsEverywhere - booking woman in tech

April 23, 2017


Introduction


It is most rewarding experience to learn and score full 30 points on this algorithm called Email Everywhere. Julia did not have time to practice C# code to write a min heap or max heap using array. She tried so many things but this time she borrowed the code from the internet, and then make it work for the algorithm.

It is a good experience to write brute force solution, and then continued to improve and solve the problems. Look at the submission of the algorithm, Julia learned the min heap and algorithm design through the contest. Well done. Here is the report of submission:



From 2.5 to 4.17, and then 19.17 and then 30 full points, Julia tried to review each step and then write down how she works better next time.


Code review


The last submission with full score 30 is here.

Back to first try, wrong answer and timeout, pass 4 test cases, scored 2.5. Code is here.

Second try, scored 4.17, no more wrong answer. Code is here.

Third submission, scored 19, code is here.

B.Available - Booking woman in tech

April 23, 2017

Introduction


Code review 


The submission of C# code is here. Score 10.77, maximum score is 60.

Manhattan 2 - booking woman in tech

April 23, 2017

Introduction


It is most favorite algorithm in the contest. The algorithm is to find the optimal solution using DFS/ BFS, and also need to work on memorization to remove duplicate work, take care of timeout issue.

The problem statement is here.

Julia spent so many hours to work on DFS - recursive function, or using  a stack to do the work. Search the blog using DFS and then a lot of work will be listed here. But Julia worked on in the contest more than 6 hours from 2 pm to 8pm, and she still could not figure out 5 wrong answer test cases.

Algorithm problem solving is such a fun activities. Through those long hours problem solving, Julia now knew so many things she had to learn and work on. This booking contest just let her know that how challenge the work will be if she lands  a job to deal with millions customer.

Code review


The last submission in the contest scored 30 out of maximum score 50. The code is here.

5 runtime error, not timeout.

The submission scored 25 out of maximum score 50, timeout 5 test cases at least. The code is here.

The submission score 23.75, timeout and runtime error. The code is here.

This is the great workout for Julia to learn the algorithm. She replaced recursive solution with a stack, and then she worked on the idea to avoid duplicated calculation. Every node is visited and then sum and maximum value will be recorded, only better candidate can allow to visit again.

From the score 23.75 to 30, Julia worked on the problem solving, understood how important to keep the code as simple as possible. She worked on her last submission to clean up code more than 30 minutes. She learned to discipline herself to show clean and readable code.

Actionable Item


4/26/2017 9:32pm

Work on the test case 9, and then figure out why it is a wrong answer for my submission. Look into the issue. Figure out the solution to pass all test cases first.

Post a code review once I can write a solution to pass all the test cases. Right now, there are 78 players scoring full score 50 in the contest.

Similar question "KnightL on a chessboard" was asked before, the link is here. The code review is so great and Julia applied the tips from code review through the contest.

4/28/2017
After studying the test cases, Julia found one counter example of her assumption - her design flaw:
matrix
1 1 1 1 1 1 1
1 1 6 7 8
1 6 1 1 1
1 6
1 6
1 6
1 6 6 6 6 6 6
seconds is bigger than 14, for example 20 seconds, we need to count 6, 7, 8 for biggest path 1 1 6 6 6 6 6 6 6 6 6 6, extra 5 seconds will take a visit nodes 6 -> 7 ->8 and back to 6.

Follow up 


May 14, 2018
I reviewed the performance of the algorithm in the contest. I did spend over six hours, and submitted over 20 times to try to get more points. And I read the last submission with a few functions, in total there are more than one hundred lines of code. It is too complicated and not practical approach from my point of view.

I believe that the dynamic programming solution can be found and should be easy and clean code. I like to plan to work on this algorithm again, and test how good I can be compared to more than 12 months ago.

Here is my C# algorithm written using dynamic programming.