Monday, July 31, 2017

Hard level algorithms (II)

July 31, 2017

Plan to work on Top facebook hard level algorithms. Plan to read those 11 algorithms and think about 30 minutes a time.

Here is the link.

Here is the image.

Hard level algorithms (I)

July 31, 2017


It is a good idea to have some hard level algorithm in your mind when you go over routine daily work. You will find yourself to be more motivated and more efficient to live and work every day. Because you are searching the great ideas and read a lot of people's code with various languages, you will certainly appreciate how luck you are to have a software engineer job and always find yourself work on some easy tasks. Do not waste your brain power, get it challenged more often.

Let us work on Top Google Questions on hard level Leetcode algorithms.

Hard level algorithms 

First, it is very helpful to show the image of those algorithm. Plan to spend 2 hours to read those 17 algorithms and think about ideas to solve the problems. 

The link is here

Leetcode 632: Smallest Range

July 31, 2017

Plan to work on the hard level algorithm called "Smallest Range".

Leetcode 315: Count of Smaller Numbers After Self

July 31, 2017

Plan to work on the hard level algorithm called "Count of Smaller Numbers After Self".

Leetcode 301: Remove Invalid Parentheses

July 31, 2017

Plan to work on the hard level algorithm called "Remove Invalid Parentheses". Spent over 2 hours to study the leetcode discussion, and figured out what to work on. The most important is to write code using other people's ideas, Julia found one person to summarize the solutions  through the discussion. Julia likes to apply Terse, Expressive, and Do one thing  (TED) principle she learned through course clean code. She likes to go over the handout of the course and apply some notes to her practice. The handout link is here.

Three code principles are outlined in the article called "3 Core Principles to Write Clean Code".

Depth first search I

1. Plan to study Java solution provided by a Google engineer first. Here is the link.

Spent over 2 hours to study the code, Julia wrote one with three test cases. Here is her C# code. Use readable function name, C# code is here.

Depth first search II

2. Plan to study Java solution provided by dietpepsi. Here is the link.

Spent over 2 hours to study the code, Julia wrote one with three test case. Here is her C# code.

The design idea is to scan the string twice, first scan is to remove the invalid ')'; then reverse the string with removed invalid ')', in other words, scan right to left virtually; this time is to remove invalid '('.

After removing invalid ')' and '(', reverse the search and then add to valid strings list.

Breadth first search ( no pruning )

Plan to study the discussion, the link is here

C# practice code is here

Breadth first search ( pruning )

Plan to study the BFS solution written in Java. The link is here.

A few ideas are applied to prune the BFS algorithm.

Julia's C# practice is here.

4. Plan to read this review of all solutions. The discussion link is here.

5. Plan to study the analysis written in Chinese:

对于一个字符串,在任何时候如果 ')' 的个数多于左括号,则说明从开始到现在位置必然可以删除一个')'.而这段子串可能包含多个')',删除哪一个呢?当然删除任何一个都可以.

例如对于()())(),从开头到 s[4] 位置构成的子串多了一个右括号,因此我们需要删掉一个,而这个子串有三个右括号,但是只会产生2个结果,也就是会有一个重复值.所以在删除括号的时候,为保证不会产生重复值,需要记录一个最后删除的位置,这样可以使得在接下来删除的时候只删除这个位置之后的值.这样我们可以使得当前这一段子串不再包含多余的右括号了.这样我们可以删除了一个右括号之后合法的子串与后面还没有检查过的子串组成一个新的字符串重新开始检查.直到不再含有非法的右括号.




Plan to study C++ source code. Here is the link. The blog link is here

Leetcode 85: Maximal Rectangle

July 31, 2017

Plan to work on the hard level algorithm called Maximal Rectangle. 30 minutes a time.

Julia studied one of discussions, and then she wrote a C# solution based on the C# solution shared. Here is her C# code.

Update C# code, move currentRight variable declaration just before use. The code is here.

Leetcode 42: Trapping Rain Water

July 31, 2017

Plan to work the hard level algorithm called Trapping Rain Water.

Work on the algorithm 30 minutes a time. Go over the discussion section and make sure that Julia learns as many ideas as possible.

Leetcode 4: Median of two sorted arrays

July 31, 2017

It is the hard level Leetcode algorithm. Julia likes to learn some hard level algorithm.

First review C# practice Julia did 2 years ago. Plan to work on the algorithm. 30 minutes a time.

One hard algorithm a day

July 31, 2017


It is time to do some short research. Today Julia chooses the research topic is "One Leetcode hard algorithm a day". Because the leetcode algorithm has more than thousands submissions and also over thousands views, it is good practice to go over the discussion every day.

It is also the research Julia likes to work on, how to keep herself motivated to improve problem solving on algorithm and data structure. One thing she finds is that she spends at least one hour to go over wechat or every day, she is very interested in the entertainment news and keep update with friends. But she has to limit the consumption of those news and entertainment stories. She has to set cap on the time on those activities. Instead she started to go back to church every Sunday and meet people, have more grounded activities instead.

To be a successful competitive programmer, Julia has to get into the community of Leetcode discussion group more often, think and practice algorithm more often.

First step is to read all hard level algorithms first. At least Julia starts to think about the algorithm. Do not read discussion, think about the problem first.

Algorithm practice

Here is the webpage to list hard algorithm on Leetcode. There are less than 150 hard algorithms.

Here is the list of hard level top liked hard algorithms.

Here is the list of hard level top Amazon algorithms. (7 algorithms)

Here is the list of hard level top Google algorithms. (17 algorithms)

Here is the list of hard level top Facebook algorithms. (11 algorithms)

Plan to read about "Serenity prayer".

Sunday, July 30, 2017

Leetcode 72: Edit Distance

July 30, 2017


It is such great mocking experience for Julia to work on edit distance algorithm again in 30 minutes this afternoon around 4:00 pm. Since Julia was tired and kind of sleepy, she could not hear the peer because of her speaker was turned off. It took her 5 minutes to find out, both tried to login again. The fact is that if you are tired, your will have some issues to work on the small thing.

It is good to observe that when you are tired, the thing can go out of control once a while. Julia remembered last time that she was very tired and then she worked on week of code 34 over 5 hours and did not score anything. Always get ready for the mocking!

The algorithm is hard to write. Even though it is not the first time to write it. Her last practice is documented here.

Design of Memoization

The peer helped Julia to come out the idea to design the key for memoization. Julia worked on design by going through the simple case, "heat" to "hit",  how to express distance("eat","it") using the key? Julia thought about loud, one way is to concatenate two keys like this "eat it", and she said that "it eat" should be the same as "eat it". Because Julia was too tired, she did not have a good idea. She was given a hint to use the array, use index of string, then she asked the idea using int[2] and define the comparer function.

The peer gave her hint to use jagged array memo[i][j], whereas i and j are the index of start position of substring.

Algorithm practice 

C# practice code is here. The code runs with a test case and the result is correct. The peer reminded Julia line 71 and 72 having an issue. Julia forgot to increment one to the distance. At the end with a test case, the peer applaused  Julia, and it was unbelievable 71 lines of code no bug.

Editorial Notes:

I practiced again this algorithm through mocking interview, I met a senior developer who has very good managing experience. He asked me the time complexity about brute force solution, I stumbled on the question.

Based on the above experience, I did not learn the algorithm very well in theory. The dynamic programming is not easy to figure out. I need to relate to a simple life experience for this algorithm. I did one later on. Here is the blog link.

Saturday, July 29, 2017

Clean code: Writing Code For Humans (II)

July 29, 2017


It is so much learning to go over the lectures again after 2 months. The lecture on is three hours 10 minutes long. The first time study is documented, the blog link is here.

In order to practice those principles like TED principle, Julia has to write down and try to have some workout first. It is also good practice to go over some lecture note before taking another mocking interview in the weekend.

To be a better programmer, stay competitive, the mocking interview is the great opportunity for Julia to learn how to work on small things each time, learn to communicate with the peer to solve problem. More practice will help Julia learn and have some creative ways to solve the problem.

July 29, 2017  10:30 pm - 11:30 pm
Go over the lecture video again

TED Principle (remember it, repeat three times! TED Principle, TED Principle, TED Principle)
Terse, expressive, do one thing
Don't repeat yourself

How to write Self-document code?
clear intent
layers of abstraction

Assign Booleans Implicitly 
Magic Numbers
Dirty                  Clean 
if(age > 21)        const int legalDrinkingAge = 21
                         if(age > legalDrinkingAge)
Encapsulate Complex Conditionals
Principle: Favor expressive code over comments (expressive vs comments, two choices, a principle?)

Be declarative if possible 
Clean -> Use LINQ
return users
   .where(u => u.AccountBalance < minimuAccountBalance)
   .where(u => u.Status == Status.Active); 
Interesting? Call it "Be declarative if possible". It is hard to related to LINQ example. 

Table Driven Methods 
- great for dynamic logic
- avoids hard coding
- write less code - Avoids complex data structures
- Easily changeable without a code change/app deployment

Friday, July 28, 2017

How will you measure your life?

July 28, 2017

It is the good habit to share a testimony when you read a book or watch a video. The book is called "How will you measure your life". The video talk at linkedin is very detail and 75 minutes. The video link is here.

It is hard to relate my life story with this book and video talk since I only spent less than 2 hours to study them. Right now, I am still watching the video and listen the talk. But I had a lot of small group meeting from 2011 to 2015, I learned and practiced a lot of talks through small group meetings.

How will you measure your life?

July 28, 2017

Plan to watch 20 minutes talk by Harvard professor Clay Christensen. The link is here. The book link is here.

Julia has a habit to check wechat once a while, every time she saw an article about the professor in business, she will google and then spend 10 - 20 minutes to do some research. First, she can learn English and improve her research skills; she can compare her research to the wechat article and see the difference.

The Chinese article link is here. The better Chinese article with more supporting arguments is here.

It is good website to read more about book while watching the video second time.

More reading is much more fun:

15 Business Theories that will improve your life - business insider article link is here.
75 minutes talk at LinkedIn, the link is here.
5 minutes reading about the book, link is here.

Becoming an outlier: Reprogramming the developer's mind

July 28, 2017

Plan to watch another course on provided by Cory House, which is called "Becoming an Outlier: Reprogramming the developer's mind".

Follow up 

August 30, 2017
Read the transcript, and then look into a few ideas shown in the transcript. 

Read the short essay written by Peter Novic, the topic is "Teach yourself programming in ten years". The article link is here

C# coding standard by - the link is here

Seven ineffective coding habits of many programmers

July 28, 2017

Plan to watch 46 minutes video called "Seven ineffective coding habits of many programmers". The link of is here.

It is better to go over slides while watching the video. The slideshow link is here.

Programmer may like to watch this course on called "Code For human".

Wednesday, July 26, 2017

Find first ancestor

July 26, 2017

Plan to study the algorithm called "Find first ancestor". The blog link is here.

Ways to climb a stair case

July 26, 2017

Plan to study the algorithm called "Ways to climb a stair case". The blog link is here.


July 26, 2017

Plan to study the algorithm called Parentheses. The blog link is here.

Flood fill algorithm

July 26, 2017

Plan to study the blog about the algorithm "Flood fill algorithm". The blog link is here.

Practice depth first traversals

July 26, 2017

Plan to study the algorithm blog called "Practice depth first traversals". The blog link is here.

Can a blog make a difference?

July 26, 2017


It is so much fun to have a new school once a while. Julia spent over three months to learn from, she was kind of getting lost in the code review but she received a lot of valuable review from JS1. The internet is big world and she never met the person and contacted him personally, the anonymity of user makes internet more interesting.

From March to July, Julia started to meet a person one by one. But she met too many people, sometimes she could not prepare very well for the algorithms used in the mocking. The experience was amazing, this mocking website machine learning algorithm really did great favor to Julia, she could not believe how she connected top talent in the world. It is like inviting people to give you guest lecture every day. Julia learned that good personality really makes life easy as a programmer, so she works hard to reduce her accent, discipline herself to prepare early, learn to be super patient.

Now Julia likes to conduct  a small research on the blog written by Aviad Ezra. Julia likes to go over around 20 algorithm one by one.

Blog study 

First one is about boggle algorithm. Julia wrote a blog on this algorithm. Julia just learned the trie again in June, 2017. The blog is here

Tree contains linkedlist

July 26, 2017

Plan to study the algorithm called "Tree contains linkedlist". The blog is here.

Design cache with auto deletion

July 26, 2017

Plan to study the algorithm called "Design cache with auto deletion". The blog link is here.

Algorithm: Possible Triangle

July 26, 2017


It is a good practice to document personal growth in terms of coding skills. Julia looked up her gmail box and found an email to read back to October 2009. Julia read the code she wrote 8 years ago, and there are so many issues in her code. What she likes to do is to review the code and write down her feelings.

Proverbs 24:16, for the righteous falls seven times and rises again, but the wicked stumble in times of calamity. 

Just be super patient to yourself. The bible teaching always use seven, or seven of seven to allow thing happen. Learn from the past mistake, it is the first step to move forward.

The problem statement is the following:

How to determine if three numbers can be a triangle, which is one with three lines with same length, two of them with same length.

Algorithm practice 

Here is the code written in October 2009, the link is here.

Plan to write the function and give some code review compared to the previous one.

It is a long journey, after 8 years, Julia went back to her gmail box and found this algorithm. She did fail the phone screen with the code; so she reviewed her own code, and wrote a new one. Here it is the new version, it took her 10 minutes to write. Julia will write down some code review as well.

Code review

Code written in October 2009, the link is here.
Code written in July 2017, the link is the new version.
Highlights of code review:

1. Function name should be meaningful. PossibleTriangle function name is better than the name called "test". It should be more than just to check if the numbers can form triangle, afterwards, it should be checked if the three edges are the same length, called equilateral; or two edges are the same length, called isosceles; or none of two is the same, called scalene.

2. edge case, exclude negative values;

3. Line 40, declare an array, line 41, sort the array. We like to make it simple to check any two edges's sum is bigger than the third edge.
We only need to compare two smaller edges's sum to the largest edge.

4. line 44, add comment to explain the checking and the logic of trigonometry.

5. line 51, line 52, declare two bool variables, check the triangle is isosceles only if it is not a equilateral.

6. Add some test cases to make sure that code works, pass unit test cases. C# Code is here with 4 test cases.
Julia learned a few thing after watching the course: "code for humans". Julia also learned to use Array class to sort the number first, and then use explicit bool variable to define two things.

Actionable Item

Plan to watch another course on provided by Cory House, which is called "Becoming an Outlier: Reprogramming the developer's mind".

9/11/2017 8:58 pm
Review the blog possible triangle and get some ideas about the algorithm.

I created a gist based on the email I found related to this phone screen. It is very interesting to read what I wrote back in 2009. Here is the gist.

Tuesday, July 25, 2017

System Design - Designing a URL Shorten Service like TinyURL

July 25, 2017

Plan to read the system design preview on this site.

It is the important to be specific, not be vague. Julia starts to learn system design from this easy one.

Data structures and algorithms

July 25, 2017


It is always a good practice to write down something everyday, maybe 10 - 20 minutes, work on a small research topic. Today Julia likes to review the post from Aviad Ezra on the question.

A small research 

Designing a URL Shorten Service like tinyURL - a very detail preview on

Vacation planning 2017

July 25, 2017


It is very exciting project to work on 2017 vacation planning. Last year Julia fled flied to China and spent a lot of time to watch China open tennis. She actually did not go anywhere in Beijing a few days, only spent time to watch China open all day long from October 1 to October 3, from morning to the evening 8:00 pm. Most of her favorite time was to watch tennis professional practiced in the evening.

After a short stay in the city of Beijing, Julia will fly back to her home town and visit her family over there.

Vacation talk 

Vacation is fun but also Julia had to deal with jet lag; it is best to live in a nice hotel, and then spend a first 2 - 3 days vacation to overcome jet lag, and also enjoy some sightseeing. The October weather in Beijing is perfect, and Julia has good time to enjoy the city. 

But it is also good to get prepared better, it is very important to get China cellular phone setup, the taxi service through cellular phone will make things so easy and convenient. 

Monday, July 24, 2017

System design: a chat system

July 24, 2017

Plan to read the article written by Aviad Ezra. The link is here.

Power Set

July 24, 2017

Plan to study algorithm blog called "power set" written by Aviad Ezra.

Plan to study Leetcode 78: Subsets, medium level algorithm. The discussion link is here.

Boggle - find words in matrix of letters

July 24, 2017

Plan to study the algorithm Boggle coding blog. The blog link is here written by Aviad Ezra.

There are a lot of thing for Julia to learn through those blog and code sample. Let us read words from Aviad Ezra together in the following:

Learn: Cracking the interview, solve all 189 questions.

Practice: Nothing beats mock interviews. It will boost your confidence and you’ll learn a ton from having someone watching you and listening to your explanations while you solve coding problems. You can pair with a friend or use one of the free peer-to-peer mock interviewing platforms. You don’t need to sacrifice your first interviews just to get hands-on practice.

Think fast: Developers that can think on their feet do much better in coding interviews. Practice in as many competitive programming sessions as you can.

Before you lost hope, keep in mind that there's a finite number of algorithms topics and only a handful of data structures that are used in the interviews.

Those words from  Aviad Ezra are so encouraging, Julia wrote her own blog about "Can mocking make difference?". First time she learns to work with people, share with people, learn from people on small things, like presenting her face in the centre through the video, ask good questions, give good hint, form a quick friendship etc.

In the following, Julia uses Leetcode 212 to help herself review Trie data structure and learn how to apply same algorithm as Boggle classified in Leetcode.

Leetcode 212 - word search II

Review Leetcode 212 last practice using Trie. The link is here.

It is so surprising that learning Trie and practice depth first search is most fun activities in the summer of 2017. Julia has to warm up the algorithm, play with one test case with Trie class, and also make the code more readable. Here is the warmup C# code using Trie data structure, recursive function calls. The solution is optimal and also pass online judge.

It is also a good idea to discuss why Trie is needed for better time complexity.

Brute force solution is to go over each word in the dictionary, and then try to find it in the matrix. The total number of search using DFS is m (words) * rows (matrix) * columns (matrix).

The brute force solution has timeout issue through Leetcode online judge. We like to review why the time complexity should be better.

Let us go over dictionary with 4 words, "aaa", "aaaa","aaab", "aaac". If we pre-process the dictionary and store all words in a Trie, and then we do not have to go over each words to search matrix. We only need to go over each element in matrix as start char in a word, search the trie to find match words using recursive function. The number of search using DFS is rows (matrix) * columns (matrix).

Second advantage related to the above 4 words ( "aaa", "aaaa","aaab", "aaac") is taking advantage of Trie data structure. The space complexity of Trie is better compared to hashset or hashtable. The same prefix "aaa" is only repeated once in the Trie.

This hard level algorithm applying Trie will be Julia's most favorite algorithm in the month of July 2017.

One of practice in 2017 is prefix neighbor on hackerrank, Julia asked the code review on

July 26, 2017

Trie against Hashset

Related to the test with a dictionary "aaa","aaaa","aaab","aaac","aaad", let us work together to talk about the difference.

For example, if the dictionary is saved in hashset, then go over each word in the dictionary, try to find word in matrix.
For example, "aaab", the first three letters has to be compared and they are the same first, then the last letter will be checked. Same will be applied to another 4 words. In total, the prefix "aaa" will be compared exactly 5 times in order to find those 5 words.

Can we do better? Just compare the prefix "aaa" once? Cetainly we can. We can save the words in a trie instead of hashset.

|\  \  \
| \  \  \
|  \  \  \
a  b  c  d

Trie efficiency talk 

It takes some time to get comfortable to design a Trie. So far, Julia has written a Trie implementation more than 4 times in C# last 3 years. Given the fact that she has worked on computer science more than 20 years, if she writes a algorithm every day, then she will write 60,000 algorithms. It is smart to focus on one simple thing, write code for algorithm and data structure, no matter life goes up and down, make it a hobby.

How to design a Trie so that the space complexity is minimum?
For example, the dictionary has the following words, "aaa","aaaa","aaaaa","aaaaaa".
How to store them in Trie efficiently?
a   word: "aaa"
a   word: "aaaa"
a   word: "aaaaa"
a   word: "aaaaaa"

The above diagram shows that those four words are saved in a Trie. How many char 'a' are saved in Trie, only 6, not 3 + 4 + 5 + 6 = 18 chars. Four words are saved along the trie nodes.

Every node can represent a word, it does not have to be a leaf node.

It is a smart decision to write down some test cases, so next time when Julia comes cross an algorithm, she can quickly relate to the test cases and figure out the advantage of using Trie.

Coding blog study

July 24, 2017

Plan to study the coding blog written by Aviad Ezra.

System Design: Predict User Purchase

July 24, 2017

Plan to do some research on a system design topic called "Predict User Purchase". 

Julia came cross the system design small talk in Chinese, she likes to look into the design: 

Predict User purchase
(先分析什么因素判断用户买不买这个商品,浏览记录,购买记录,在页面停留时间,浏览这类商品的次数,现在火的top 100商品等等。然后分析架构,
给的答案是首先master slave避免single point failure,用户点击商品后先通过dymanic dns look up找到距离最近的CDN,然后http request传过来给那个cluster的master server, mater本身有cache看看这个请求的结果是不是已经cache过了有的话直接返回(这里cache的是这个请求对应的购物车html页面),没有的话master做负载均衡下传给空闲slave server(rmi call), slave有自己的local cache因为对这个预测结果每个slave cache可以不consistent, 可以不用时刻recon每个不同的server cache。所有的数据存储都用in memory database并设置time to live, 因为这个是一个读取大于写的系统数据也不需要持久化不用支持transaction, scale也更容易。master如果挂了重启就可以,因为都是预测数据丢失了也无所谓。如果要更优化可以在浏览器端也做一层cache,如果用户反复点击同样的商品,就不用每次都make http call了)

Plan to do some research on this topic. 30 minutes a time. 

Maximum Gcd and Sum (III)

July 24, 2017


"Maximum Gcd and Sum" is the algorithm related to great common divisor, and prime number technique called sieve of eratosthenes is used in the optimal solution.

The algorithm is the first medium level algorithm in week of code 34 on Hackerrank. Julia spent more than a few hour in the Saturday of July 21, she did not come out the solution to fix the timeout and run time error issue.

Here is the optimal solution after the study of editorial notes.

Plan to do time complexity analysis on test case 1, 400,000 is the length of testing array.

Week of code 34 (II)

July 24, 2017

It is early in the morning 12:09 am. The contest just ended 9 minutes ago. Julia spent a few hours this Sunday from 6 pm to 12 am to work on the contest, but she did not score anything. She did not write any code either.

Sunday went away fast. Julia got up around 9:30 am, and spent one hour to work on the contest, and then she left home around 11:20 am for church service. She came back to home with friends to prepare lunch around 2: 30 pm, and then had good time until 5:30 pm.

It was really hard to work on the algorithm. Julia felt a little sleep around 6:00 pm, and then she spent one hour to talk over the phone.

Julia likes to work on those algorithm next week and catch up more on training. Stay positive.

Sunday, July 23, 2017

Leetcode 347: Top K Frequent Elements

July 23, 2017

Plan to work on Leetcode 347, the algorithm called "Top K Frequent Element".

C# solution using Dictionary and bucket sort. The link is here.

Path Statistics

July 23, 2017

Plan to work on the algorithm called Path Statistics which is expert level algorithm in the week of code 34. The problem statement is here.

Now it is 11:28 pm, 32 minutes before the contest ends.

Julia likes to write some code for this algorithm, and see if she has any chance to score anything.

Magic Cards

July 23, 2017

It is the first expert level algorithm in the week of code 34 on Julia likes to read the problem statement and spend 30 minutes to work on the problem first.

Here is the problem statement.

Now it is 6:27 pm, the contest will end in less than 6 hours.

Julia likes to read every algorithm in the contest. It is hard for her to work on the algorithm in such a short time.

Recurrent on a tree

July 23, 2017

It is the hard level algorithm in week of code 34, hackerrank contest. It is 5:24 pm July 23, 2017. Julia plans to read the problem statement in 30 minutes, and do some research on the algorithm in a hour.

The problem statement is here.

Leetcode 581: Shortest Unsorted Continuous Subarray

July 23, 2017

Plan to spend 30 minutes to read the solution of Leetcode 581 Shortest Unsorted Continuous Subarray. The solution link is here on Leetcode discussion section.

Saturday, July 22, 2017

Leetcode 152: Maximum Product Subarray

July 22, 2017

Plan to work on Leetcode 152: Maximum product subarray.

Same occurrence

July 22, 2017

It is the second medium level algorithm in Hackerrank week of code 34. Right now, Julia has to start the algorithm and try to make some progress. It is 10:17 pm. Julia likes the challenge.

Plan to study Leetcode contiguous subarray related algorithms first.

Plan to work on Leetcode 53 (easy) and Leetcode 152 (medium level) first.

Maximum Gcd and Sum (II)

July 22, 2017

It takes a lot of time to move forward with timeout issue on this algorithm. Julia likes to check her progress and stay positive all the time.

Here is her code submission in second time, now it is 8:00 pm, 7/22/2017.

The original points for the algorithm is 25, but so far only 16.4 available for Saturday player. Julia only made 20% of available points 16.4. Continue to work on it!

It is 10:27 pm. Julia worked on timeout issues, now she came cross runtime error issue. Most of her issues are runtime error, only two cases are timeout.

Follow up after the contest

July 24, 2017

The code submitted in the contest is here. The idea used in the algorithm is to find prime factors for each number in the array.

Prime number factors

July 22, 2017

Plan to work on the algorithm called "Efficient program to print all prime factors of a given number".

Maximum Gcd and Sum

July 22, 2017

Plan to work on the medium level algorithm called "Maximum Gcd and Sum".

Analysis and investment of time

It is running late for Julia to work on week of code contest. Julia read all discussions and this medium algorithm only has single digit successful rate after a few days.

Julia likes to do some research to help herself to solve the problem. She could not afford to spend a few hours without gaining some new skills.

She decides to work on a few related algorithm first.

First one is called "Efficient program to print all prime factors of a given number".

Plan to read the topcoder article called "Prime numbers, factorization and Euler function".

Can I be a manager?

July 22, 2017


It is a good topic to come into Julia's mind last few days for her next topic of research. Julia likes to do a short research, maybe 30 minutes, maybe more. One research topic is to be a manager. How to be a manager? Julia knows that so many of her friends at Florida Atlantic University back to 1998 to 2006 are managers and principle scientists right now.

It is more interesting to be a manager to manage a software team. One thing Julia likes to study is Amazon principle leadership. She also likes to follow managers on

Recently, Julia visited her 2nd or 3rd connection with managers title working in Amazon, so she tried to follow every manager in her circle. But she only followed 2 managers yesterday and then Linkedin gave her warning messaging "Jianmin, you've reached the commercial use limit. Please upgrade to LinkedIn Premium Business Navigator, or Recruiter to get unlimited people browsing."

Julia likes to talk about warnings she got in her life last 6 months, and then how she works hard to get back to good standings.

Search for warnings

Julia was busy with her full time job and also training in algorithm and data structure. And then she had a car accident in February, 2017. It is such a surprise, but Julia analyzed the problem before. Every accident there is over 10 times warnings. Julia did not have time to catch them and then the accident happened finally.

Get a good thick skin

Another thing is how to keep up with her siblings. Julia has an elder sister who retired 2 years ago as a high school teacher in China, she has visited more than 20 countries. And she is enjoying life with no worry about working full time or part time. Julia was busy with her hackerrank contest and she also was busy with a lot of sports training ideas. So what Julia does not understand is that how important is to keep up with your family and get more fresh ideas about life and everything. Julia stopped attending church last 6 months and all her activities were limited to home office and office at work, one day she found out that she likes to get into other people's life, so she spent over 6 hours to watch Netflix TV series, she suddenly figured out that is most fascinating creative story in her last 6 months. Julia has to learn how to communicate with people retired with financial freedom, Chinese. Do not get hurt if you are joked how poor as a Canadian and how little wealth you have as a Canadian.

Stand on ground 

Now Julia knows that if she attends the church regularly, talk to her family regularly, she will feel less lonely, spend less time on internet on week days, on Chinese wechat social website, she may have a good sleep the whole week. She can maintain more healthy life style, and also maintain great productivity in other area.

Choose activities more grounded

Julia was busy with mocking interview last 3 months. She practiced more than 80 times. She tried to catch up people skills, learn how to work with people, specially on career growth, technical strength on data structure and algorithm.

Bible teaching is very good on this. Ecclesisters 4:10, if either of them falls down, one can help the other up. But pity anyone who falls and has no one to help them up. 

To gain technical strength, specially improve algorithm and data structure problem solving, you can not do it alone. The efficient way is to get connected to people in more meaningful way. One viewpoint is that Linkedin is not helpful, waste of money; Julia did some research on Linkedin connection, how much contribution comes from linkedIn last 12 months. How she makes connection last 3 months through mocking interview. How much knowledge and skills she gains to work with peers. 

One thing she compared is the difference. She met a person connected through LinkedIn after a meetup whereas she met a person through mocking interview second time or she got connected again through emails with the person after mocking interview. 

Face paralysis research

July 22, 2017

Life is a great teacher, if you live happy and healthy, and get along with friends and family, you will have a lot of lessons to learn. Julia is experiencing a lot last six months, she studies a lot of things.

Aging is the big topic for her to catch up. Julia is so busy with algorithms, Leetcode and hackerrank contest. And once a while she pushes herself to rewrite a program at work and she joked about she is writing a new book because of the code has over 100 pages long. She is such a great writer and she enjoys so much for the great performance of new updated program. She knows that her new schools taught her so many lessons and she was definitely happy to apply everything to her own work.

Recently in summer break, Julia has a young sister who is a college teacher, she shared her story about face paralysis. So Julia has to start to learn how to keep our face healthy, avoid face paralysis.

Mom with a dementia

July 22, 2017

Life is such a great teacher. Julia was taught so many lessons. Last 2 years her 86 old mom lives in 24 care hospital as a dementia senior citizen in China, she visited her mom every year and visited the facility, she knows how hard people are making a living once the aging is really getting those people. She watched her mom progressed from 80 years old to 86 years old, how she was panic four years ago since my sister as a physician told her that she will have dementia. My mom struggled to stay home with a full time care over 2 - 3 years and then finally moved in the 24 care facility in a hospital.

One of videos Julia recorded makes her almost cry to watch is to document her mom only remember her 20s songs but she could not memorize the latest activity. Video is here recorded 3 years ago.

Another video is about her mom to celebrate Chinese new year in 2014.

Last year when Julia visited her mom, her mom was not able to open mouth when some one feeds her. The nurse has to squeeze her nose in order to let her open mouth. And she lays on bed so that the career can feed her food. Life is such a gift for us, we have ability to eat, think and live independently.

Julia was so thankful to her sibling - her sister is a physician, a psychiatrist, she knows a lot about dementia, and helped my mom go over so many years struggle and still being able to live as a human being.

Face paralysis research

July 22, 2017


Life is such a great teacher. Julia was taught so many lessons. Last 2 years her 86 old mom lives in 24 care hospital as a dementia, she visited her mom every year and visited the facility, she knows how hard people are making a living once the aging is really getting those people. She watched her mom progressed from 80 years old to 86 years old, how she was panic four years ago since my sister as a physician told her that she will have dementia. My mom struggled to stay home with a full time care over 2 - 3 years and then finally moved in the 24 care facility in a hospital.

One of videos Julia recorded makes her almost cry to watch is to document her mom only remember her 20s songs but she could not memorize the latest activity. Video is here recorded 3 years ago.

Another video is about her mom to celebrate Chinese new year in 2014.


Recursive function small talk

July 22, 2017


It is most favorite thing to do in the world, write a quick and short solution using depth first search, and also in recursive function call. Julia wrote a blog about her recursive function practice a few days ago, called Maze.

Today Julia spent near 30 minutes to conduct a mocking practice, and then she chose to practice one more time.

One more practice 

Given a binary search tree, write a function to return the largest smaller value in a binary search tree. Here is the C# code.

It is the first time Julia wrote this recursive algorithm. She made a few correction through whiteboard testing. And then she argued that the algorithm should work, one thing is to prove that any number returned should be less than given value.

Time to share

It is so interesting that Julia did impress the peer after 60 minutes mocking interview, and the peer asked Julia how she practices. So it took extra 40 minutes for Julia to share her experience. Julia likes to get organized and give good advice to the peer.

Last 3 months Julia practiced the algorithm a few times, and she also used the algorithm as an interviewer. But she did not come out a correct solution first time.

Three things Julia shared her practice:

1. Leetcode 10 - the most important about recursion tree, return A || B || C, A is that b* stands for empty string, B is that b* stands for one b, C is that b* stands for more than once, like "bb". The recursion is in 3 branches.

It is the hard algorithm and Julia interviewed over a few people, only one person is very close to the perfect solution. The code was very clean and almost perfect. Julia learned through the experience, she was interviewed to write the algorithm twice, both of them were not correct, not very close to optimal solution at all. Julia shared honestly her experience on the algorithm.

This algorithm became Julia's most favorite one after she invested so many hours on it. She wrote a few blogs on this algorithm, the one she likes to share is here.

2. Code review on stackexchange website, her experience on code review. Link is here.
3. Refdash mocking interview.

It is the first time Julia was told to adjust the camera so that the peer can see her face impression, in first a few minutes. This is the second time Julia got complaint, first time the peer complained the echo sound, so she decided to use headset.

Friday, July 21, 2017

Do not count wrong doings

July 21, 2017


Bible teaching about love is the most important lesson Julia has. Love is patient, love is kind. One of Julia's favorite bible verse, Corinthians 13: 5, It is not rude, it is not self-seeking, it is not easily angered, it keeps no account of wrongs.  Every time Julia finds her own mistakes, she knows that she has to practice - no account of wrongs

It is still a good practice to talk about mistakes. It takes a long time to learn algorithm and data structure. Julia should complete more Leetcode algorithm after 2 years, so far she only submitted less than 100 algorithms.

Related to leetcode algorithm practice, starting from 2015, Julia found out that best place to find ideas is to go over Leetcode discussion section in March 2017. She searched everywhere, it is best place to read and learn, evaluate various solutions by going over Leetcode discussion.

It is a good practice not to blame yourself, treat yourself as a human being, accept yourself. Learn one algorithm a time.

Leetcode algorithm status report

84/620 Solved, Easy 21, Medium 41, Hard 22.

Leetcode: Meeting Room II

July 21, 2017

Plan to study the algorithm Meeting Room II.

Here is the discussion to review:
The idea is seen in the blog on segment fault. Link is here.

这题的思路和Rearrange array to certain distance很像,我们要用贪心法,即从第一个时间段开始,选择下一个最近不冲突的时间段,再选择下一个最近不冲突的时间段,直到没有更多。然后如果有剩余时间段,开始为第二个房间安排,选择最早的时间段,再选择下一个最近不冲突的时间段,直到没有更多,如果还有剩余时间段,则开辟第三个房间,以此类推。这里的技巧是我们不一定要遍历这么多遍,我们实际上可以一次遍历的时候就记录下,比如第一个时间段我们放入房间1,然后第二个时间段,如果和房间1的结束时间不冲突,就放入房间1,否则开辟一个房间2。然后第三个时间段,如果和房间1或者房间2的结束时间不冲突,就放入房间1或者2,否则开辟一个房间3,依次类推,最后统计开辟了多少房间。对于每个房间,我们只要记录其结束时间就行了,这里我们查找不冲突房间时,只要找结束时间最早的那个房间。

Here is the Java code to review.

Go  over the leetcode discussion and try to find out good ideas. Plan to study code provided by high reputation engineer Su Yong, code is here. And plan to spend time to read ofLucas to explain the Su Yong's design in detail in this discussion link.

Thursday, July 20, 2017

Leetcode 311: Sparse matrix mulitiplication

July 20, 2017

Plan to do some research on this algorithm called "Sparse vector dot multiplication". 

It is very interesting to learn something from great sharing in Chinese. 

sparse vector dot multiplication,这道题我当时并没有准备到,但是正因为如此,我认为我跟面试官的交流给我加分了不少。面试官首先问我每个vector很大,并不能在内存中存下,该怎么办,我说只需要存下非零的元素和他们的下标就行,然后询问面试官是否可以用预处理后的这两个vector非零元素的index和value作为输入,面试官同意后快速写完O(M*N)的代码,M和N分别是两个vector的长度。面试官说这两个输入如果是根据下标排序好的话应该怎么办,我说可以遍历长度较短的那一个,然后用二分搜索的方法在另一个vector中找index相同的元素,相乘加入到结果中,这样的话复杂度就是O(M*logN)。这时,面试官又问是否可以同时利用两个输入都是排序好这一个特性,我在这个地方有点卡住,但是在白板上写出一个test case,试着用可视化的方法帮助我来进行思考,同时面试官给了一些提醒,最后写出了O(M + N)的双指针方法,成功结束最后一轮面试.

Work on the algorithm based on the time complexity: 
1. O(M*N)

2. O(M*logN)

3. O(M + N)

Read the algorithm on code review

Read the leetcode discussion. Link is here

Coding blog from grandyang. Link is here

Google search, Leetcode 311: Sparse matrix mulitiplication. There are a lot of coding blog on this algorithm. 

Leetcode 15: 3 Sum - optimal time complexity

July 20, 2017


It is most challenge work to read a paper related to Leetcode 3 sum, called "Threesome love triangle". 24 pages paper, read 30 minutes a time.

Paper reading 

It is so interesting to learn the algorithm and data structure research. Julia spent over 30 minutes to study one of authors - Seth Petti who works for university of Michigan computer science department. The ranking is very top in USA universities.

Julia joined the community of theorectic computer science on first time in March 2017 and tried to explore the depth of the knowledge and get more interested in computer science theory. One of her professors is Aaron Meyerowitz in Florida Atlantic University. Julia took set theory math graduate course from 1996 to 1997 in Florida Atlantic university, she had a very small class with a few math graduate student. First time she understood what makes a great professor, just check the problem he works on and how difficulty it is. Julia admires hard work spirit.

What does Julia look for when she browses the research of a professor? She believes that this is one of top-tier theory professor in the world.

Relate to personal research and course study, it is two times decision for Julia to skip mathematics graduate research in her career. In 1989 she chose to change major from math to engineering in Shanghai Jiaotong university, and then in 1996 she chose to change math Ph.D. program to computer science master program in Florida Atlantic University.

Do Julia like complicated math problem? How does she work on her problem solving skills?

Leetcode 486: predict the winner

July 20, 2017

Plan to work on Leetcode 486: predict the winner.

Wednesday, July 19, 2017

Leetcode 179: Largest Number

July 19, 2017

Plan to work on the algorithm which is a medium level called "Largest Number".

Week of Code 34

July 19, 2017


It is time to play a hackerrank contest again called "Week of Code 34".

Passion is gone

Julia got her first gold medal in the week of code 33 because she worked hard on the contest.

Now it is time for another week contest, but Julia was too busy in weekdays, she did not have time to work on any algorithm. Another thing she missed is her passion for the contest. Passion is so easy to go away, Julia was busy first two days in the week to review coding practice last 3 months, and the rest 3 days after work, she played tennis Wednesday, and Thursday she rested and Friday she worked on other algorithms.

Sponsor application project

July 19, 2017


It is very interesting to work on sponsor application project. Julia started to watch videos related to the sponsor application project, and she started to learn things day by day. She likes the project.


It is better to write down her most favorite videos about the sponsor application process. 

Why the delays? Link is here

Sunday, July 16, 2017

Leetcode 146: LRU cache

July 16, 2017

Plan to study the algorithm LRU cache through the leetcode discussion. The practice in 2016 is documented in the blog.

Recursive function design talk

July 16, 2017

Train insane or remain the same - Get recursive function training one more time!

Maze algorithm

Given an array, there is only one item is value of 9, all others are 0 or 1. 0 stands for the exit is not availabe, 1 is ok to continue. Make a judgement if starting from (0,0), 4 directions: upper, down, left and right, and see if there is path to find 9.

Plan to study the code written in Java first. The code is here.


Using queue, the C# code is here.

Using queue, but four directions are written more clearly, C# code is here.

After 90 mocking interviews, Julia knows that it is important to write a short version solution in less than 5 minutes, without any bug. So she decided to write a recursive solution using depth first search, she ran into stack overflow issue. It took her over 10 minutes to figure out the issue, mark the node visited on line 46.

Here is the C# version code using recursive function. The goal is to write in less than five minutes, and pass the test case in less than 10 minutes.

In order to shorten the time to write code, Julia spent hundreds of hours to learn recursive function. One of her most lesson learned through mocking interview is the bug she found, documented in the blog called Leetcode 10: regular expression match.

Ask a vote?

Which version of code you will choose to write? Julia learned the lessons through years, she learned from 90 mocking interviews, she still could not nail down the most important solution using recursive solution in less than 5 minutes, today, July 18, 2017.

Just like a song, Julia you have to memorize the lyrics, you only have 4 sentences to remember. First one is to return false, second one is to return true, third one is to set to 0 as marking visited, and then fourth one is to call recursive function for 4 possible neighbors. In other words, here is the transcript to remember:
Line 8           return false
Line 13         return true
Line 18         maze[row][col] = 0
Line 21 - 24 four recursive function calls concatenated by || operator

Shortest Job First

July 16, 2017

Plan to study the algorithm called "Shortest Job First". There are a list of jobs with execution and arrival time, shortest job will be processed first, and then average waiting time will be calculated.

Problem statement here is in Chinese.

一个处理器要处理一堆request,一次只能处理一条,如果它有几个积压着的requests,它会先执行持续时间短的那个;对于持续时间相等的requests,先执行最早到达处理器的request。问平均每个request要等多久才能被处理。input:requestTimes[],每个request到达处理器的时间; durations[] 每个request要处理的持续时间。 两个数组是一一对应的,并已按requestTimes[] 从小到大排序过。

Plan to study code written in Java first. 


C# practice using SortedSet, the code is here. 

There are seven requests in the following example, every request has two time stamps, request time and execution time. First request can be expressed in the form of (1, 2), where the request time is 1 and execution time is 2. Hopefully it makes clear to the second column with title "Process to Consider", second row (1, 2). 

Fix the bug in previous C# code because the average time should be 3.29. C# code is here, the correction is on line 71.