Saturday, January 20, 2018

Interval algorithm

January 20, 2018


It was a 10:00 AM mock interview. I met a peer who is super talented programmer and also very good mentor to write clean code and also readable code. He helped me to think about design along the 30 minutes mock interview.

Code review

Here is transcript for C# code and with analysis. I did spend first 10 minutes to write nicely an analysis for the algorithm.

Small accident

The code I wrote cannot pass the test case to find the interval, and then I could not find the logic problem. The peer told me on line 7 and line 8, I should check GetLength(0) < 1 instead. He said that he did not know C# very well, but he thinks that the checking is not necessary.

Friday, January 19, 2018

HDU-1213 How many tables

January 19, 2018


Union-find algorithm is my 2018 most popular algorithm. I like to learn it slowly. One way is to go over the blog and then follow each example in the blog related to union-find algorithm.

Kosaraju algorithm

January 19, 2018


The algorithm Kosaraju has a popular name called strongly connected graph. I plan to study the algorithm.

Recently I found a very good blog to review written in Chinese about union-find, the author also wrote another blog about Kosaraju algorithm. Here is the link.

Thursday, January 18, 2018

Data structures and Algorithms in JavaScript

January 18, 2018


It is time for me to take courses from I just started monthly subscription  starting from this Monday. The first course I like to take is Data structures and Algorithms in JavaScript. The courses on the website is here to look up.

Recursive function

I really like the lecture of recursive function. I try to learn from the teacher so I can apply the techniques in my daily mock interview practice.

ESRI - Quick study

January 18, 2018


It is so exciting to learn ArcGIS, I have good time to learn how the software helps to change the world, and make the location information so valuable to our daily life, business and make our lives much better.

I plan to spend 30 - 60 minutes to read blogs written by China ESRI. The link is here. And also I plan to read the articles related to the products.

Kruskal's algorithm Wiki article

January 18, 2018


It is the very good investment of time to read the article of Kruskal's algorithm on the wiki page. What I do is to go over each word and each sentence slowly, write down some new terms I like to learn. Today I spent over 30 minutes to read the article.

Kruskal's algorithm 

Plan to spend 20 minutes to read the article first.


minimum-spanning-tree algorithm
greedy algorithm in graph theory

minimum spanning tree

a subset of edges that forms the tree that includes every vertex, where the total weight of all the edges in the tree is minimized.

How to read the algorithm Kruskal's algortihm

How to read the graph simulation of steps: b and e are added, but there is a cycle.

Average performance:  O(|E|log|V|)

Worset-case space complexity:

Prim's algorithm, Reverse-delete algorithm, Boruvka's algorithm

comparison sort

disjoint-set data structure
union by rank

(counting sort or radix sort)  Ackerman function

induction -


Leetcode 84: Largest rectangle in histogram

January 18, 2018


Coding is always best time for me to learn the algorithm right now. What I do is to get Java code from the blog I like most and then rewrite in C# code, and then work on the code to match the design. After coding, I like to remind myself do whiteboard testing, do not use debugger, go through the test case in Leetcode 84, and go over each line of the code, run the code. I fix all the issues in the coding styles, including variable names, function name, function arguments, how to put comment to align with the code, make the code more readable.

Now it is show time to present my practice C# code.

Code review

C# code is here.

Leetcode 84: Largest rectangle in histogram

January 18, 2018


It is the hard level algorithm and it can be solved used stack to achieve the optimal time complexity O(N) where N is the array's length. The algorithm is called largest rectangle in histogram.

On January 17, 2018, I had a mock interview and I was asked to work on the algorithm. I went through the brute force solution first, but I did not come out the optimal solution to lower the time complexity to O(N).

One more practice 

What I like to do is to study one blog I like in June 2015, and then rewrite the notes and also write the C# code as well. It is very easy to look up past practice, here is my blog to document the practice in June 2015. At that time, I was shy and did not write down my thinking process to learn to solve the problem. 

First, I rewrote the note to make it more readable, and then saved a gist. Here is the gist. 

Analysis of the algorithm

Most of important is to write down the analysis, and that is something lasting longer than coding itself. Specially if I draw something to highlight the main design ideas and it will be extremely helpful to bring back the memory.

This time I drew one to help myself learn the design using stack, check upward and downward.

The main idea is very simple to explain in Chinese, let us take a look at notes in Chinese first, and then I quickly explain them in English.

Going upward

When the graph is going upward, in detail, current index is i, next step is i + 1, and height[i] < height[i + 1], there is no need to calculate the area. Since it is getting bigger value when i moves to next value.

Going downward

When the graph is going downward, in detail, current index is i, next step is i + 1, and height[i] > height[i + 1]. it is time to calculate the current rectangle's area.

Get help from a stack 

At the current index i, only right end's index is known, how to get the left end's index? So in order to iterate the array, a stack is need to maintain the backtracking history.

How to design a stack?

In this stack the right end's index is saved to the stack, but when is time to push into stack? Every time there is element in the array which is bigger than the top of the stack, push the index to the stack. Otherwise it is time to calculate the current rectangle's area and compare to the largest area.

Every algorithm will become one of your valuable weapons 
until you teach some one and show him/ her how it work.

Wednesday, January 17, 2018

Leetcode 684: redudant connection

January 17, 2018


It is the second time to meet the peer again in less than one week. Julia chose to give a medium level algorithm for peer to solve, Leetcode 684: redudant connection.


Here is the transcript for the discussion.

Highlights of good things in discussion

Peer did:

1. First the peer came out to check if the graph has a cycle

2. Second the peer drew a more complicaed tree, and then try to add one edge to make it a cycle

3. Third the peer write down a list of graph algorithm he worked before.

I try not to give out hint explicitly. So what I talk is about the example a tree drawed by the peer how node 1 is connected to node 7.

What is the connected meaning for us? The nodes are connected.

Also, I added one more graph algorithm called Kruskal algorithm, and then share the wiki page for the algorithm. I talked about the algorithm for minimum spanning tree using disjoint set data structure. And then I asked if the peer knew the data structure before.

I explained the data structure, what is for, why we need this data structure. Since the path from one node to other node is not needed, all we care about is if two nodes are connected. We do not need to search a path from one node to other node.

At last, I tried to give the explanation how to solve it in less than five minutes.

Example 2:
Input: [[1,2], [2,3], [3,4], [1,4], [1,5]]
Output: [1,4]
Explanation: The given undirected graph will be like this:
5 - 1 - 2
    |   |
    4 - 3         

Julia's explantion:

At the beginning, each node has its own set.
{1}, {2}, {3}, {4}, {5}.

[1,2] first edge is to connect 1 to 2, so {2} likes to join {1].

{1} <- {2}, {3}, {4}, {5}.

we have {1, 2}, {3}, {4}, {5}.

[2,3] second edge is to connect 2 to 3, 2 is not the set, but 3 is not in the set.

{1, 2} <- {3}, {4}, {5}
we have {1, 2, 3}, {4}, {5}

[3,4] third edge is to connect 3 to 4, 3 is in the set, but 4 is not in the set.

{1, 2, 3} <-{4}, {5}
we have {1, 2, 3, 4}, {5}

[1, 4] fourth edge is to connect 1 to 4, 1 is in the set, and 4 is also in the set. Then we know that node 1 and node 4 are connected, but direct connected edge 1 to 4 is to be added. Then edge [1, 4] is to form a cycle.

Leetcode 84: Largest rectangle in histogram analysis

January 17, 2018


It is 10:00 pm mock interview. The peer gave me the algorithm Leetcode 84: largest rectangle in histogram analysis to solve.

Algorithm analysis

The peer gave me his analysis using stack, and how to store the stack with (value, index). The discussion link is here.

Mock interview

Leetcode 84 is the hard level algorithm. I did not come out the optimal solution using time complexity O(N), and then the peer reminded me to go over upward test case like [1, 2,3, 4, 5] and then go over downward test case like [5, 4, 3, 2, 1]. And then the peer gave me the hint and then I came out using stack to push previous nodes into the stack, but I did not have idea how to manage the stack, when to push into the stack and when to pop the stack.

The peer went over quickly using the example to explain the idea.

I know that it takes me 10 mock interview practice to learn a hard level algorithm Leetcode 10: regular expression matching.

Actionable Item

Review what I did in the past on this algorithm. I did practice the algorithm in June 2015, here is the blog.

Leetcode: The skyline problem

January 17, 2018


It is hard level algorithm, some of us categorize the algorithm as binary index tree. I start to work on the hard level algorithm, 30 minutes a time, called the leetcode 218 The skyline problem. So I spent 30 minutes to read the article from Leetcode discussion most voted discussion.

Plan to work on some coding. First, I like to read code written in various languages first.

Good time to read the article with good simulation of problem solving with skyline in the background image. Time is well-spent 20 minutes or so.

Catalan number

January 17, 2018


It is the algorithm peer gave it to me for a test since he had the algorithm the day before. I had to work on the algorithm called Catalan number on January 15, 2018, 10:00 mock interview. I explained the algorithm to the peer, and also showed last 3 practices.

Will write down the discussion of the algorithm here later.

Can plant flower

January 17, 208


It was the algorithm I gave to the peer in 10:00 PM mock interview on January 15, 2018. The peer wrote code with a few of bugs, and then the topic is how a senior developer face the challenge to write a production ready code in mock interview.

I showed my blog about 48 minutes performance issue in Leetcode weekly contest. And it is one of easy questions in Leetcode.

Tuesday, January 16, 2018

Code review: Binary search

January 16, 2018


It is my time to learn some new ideas to write binary search. I learned the new way to find smallest index today. But I like to look into the idea and see if there is any pitfall on that.

Code review

I like to study the code and give some code review. The code is here.

A few things I gave in the discussion:

1. Ask the question about arr[i] - i, how to prove that it is not descending. It cannot take for granted.
2. Advice to write down some analysis before writing the code; write down the constraint, what to find. The peer missed the keyword: lowest index.
3. Binary search while loop, should include = sign.
4. Coding style

Find the smallest missing number

January 16, 2018


It is another 10:00 PM mock interview. I started to work on my analysis of algorithm, I tried to put together the algorithm requirement, constraints, and my solution, time complexity, space complexity, and also go over the small case to explain the algorithm. This time the analysis of the algorithm is not up to standard I like.

Analysis of the algorithm review

Instead of doing code review, I like to review my analysis of the algorithm. I like to make it better. Clarify the question, understand the constraints, and also the problem to work on.

I also like to find a few issues in the above writing:
I should write a summary to describe the idea to solve the problem, using the extra array to store 1 if index value is found in the original array.

Here is the code with the analysis.

Monday, January 15, 2018

case study: Depth first search base case

January 15, 2018


It is another complaint from the mock interview on January 14, 2018. The peer complained that depth first search missing a base case. What I did is that I put a base case to check the matrix element is not one in four if statement, so the if statements are giant expression, but the base case is hidden.

Plan to look up the book of mathematics for computer science and look into how to solve this issue from better understanding of depth first search.

Code study

The C# code is here.

Sunday, January 14, 2018

10 things to remember

January 14, 2018


It is a busy weekend with nine mock interviews. I met very good programmers in the world, and I cannot believe that I meet so many talented programmers in such a short time period, 48 hours.

I miss the swimming pool, crystal mall shopping, walk in metro town mall, or catch some Netflix movies, I miss those weekends I spend time do other things. I was staying in the home almost all the time, I did this very often when I play hackerrank contests and try to solve medium level up algorithms from June 2016 to Sept 2017.

As a software programmer, full time eight years, this is the first time I learn that it is my job to do something, learn to get connected to other programmers. Reach out to other programmers, in person, talk face to face, and get help and encourage each other to solve data structure and algorithm problems.

There are so many software engineers in the world. I cannot meet a lot of them, nine mock interviews a weekend, that is a lot. It is like intensive training, how to be an interviewer, and I also have to write 9 algorithms a  weekend, that is a lot of writing.

10 things to remember

Here is the easy thing for me to do to end this weekend with something easy and relax. Remember the article on quora, the link is here.

It is true that those 10 things can apply everywhere, not just in mock interview, interview. It can apply to normal daily work. No one has the responsibility to train you.

You have to get those training by yourself. I am glad that I have over 100 mock interview experience, now it is around 150 mock interview experience.

1. The single biggest good engineers fail the technical interviews is because they lack the ability to showcase how they came to their solution.

One step a time. Provide facts, good arguments, and also show some reasoning.

2. Your logic wasn't actually logical.

Try to related to very simple well defined problem if possible.

3. You didn't gather requirements or ask clarification questions.

Gather requirement and clarify the question, please!

4. You think you solved the problem but you actually didn't even answer the question.

Answer the question. 

5. You forgot to consider important things like monitoring or you code isn't production ready.

Code should be production ready.

6. You took too long or too many hints.

Accomplish something. Try to solve problem at work also using limited time, 30 minutes a time. 10 minutes analysis, 20 minutes coding.

7. Lastly, your work style just doesn't fit the culture.

People skills. Always stay positive, give people good encouragement first; and then ask permission to give some feedback. 

8. The technical breadth and depth of which you went into, simply didn't meet the expectation of the level you might be interviewing for.

9. You didn't optimize for simplicity.

10. You couldn't deal with constraints and variables.

Production ready code?

January 14, 2018


Production ready code is a new concept for me, at least less than 6 months old. The concept is that we should be able to write code in mock interview which can be ready to be shipped. There are a lot of things to be considered, let me brainstorm here.

all edge cases
the code style
the correctness of the code
the maintainability,
self-document code

How to write production ready code? 

One of ideas is to work on one type of algorithm again and again. Keep writing, keep practicing. Journal the practice until we can not get it wrong.

In tennis sports training, there is a saying that "Do not stop until you get correct". It should be "Do not stop until you cannot get it wrong".

Here is another binary search practice I did this evening 8:00 PM mock interview.

Are you ready?

January 14, 2018


It is the first time in mock interview I came cross a peer who worked hard first five to ten minutes to write down his analysis and also in very structured ways. It is the algorithm called "Find largest smaller binary search tree key than given node". I have written more than five time and also I have interviewed others more than five times. Over my one hundred interview, this is the first time I read such a great analysis of the algorithm.

Analysis of the algorithm

Here is the algorithm analysis. I never know that the analysis of the algorithm is also very important part of presentation until today 4:00 PM mock interview.

Here is the link.

There is only minor thing to modify in the base case. The node may not be the leaf node all the time.

Code review

Here is the C# code after the code review. I asked the peer to add null pointer checking at the beginning and make it one of base cases. So this way the code is much simple to read and if statement do not need to check is null pointer at all. The success of coding is that base case is well-defined on line 24.

Are you ready?

This is not the first time I met a person who is working on Google onsite in less than one week. The mock interview platform provides me great training and also I just write down those peer's code and study more, I should figure out ideas for me to improve. We do not need to spend money for tutoring, just learn by ourselves.

One easy thing to learn is to write down some note related the analysis of the algorithm. Organize them so it is well-written. Write down the constraints, write down the ideas, write down the pseudo code, write down base case for depth first search if applicable.

Share some advice from the peer

I like to share some advice from the peer. Focus on soft skills.

Find smallest substring containing unique characters practice

January 14, 2018


It is the Saturday morning and I had 10:00 AM mock interview. I had a very good peer to help me to practice one more time the algorithm called "Find smallest substring containing unique characters practice". The peer also uses C# to write code, but after the peer wrote the algorithm called "Find Binary search tree successor", I compared his performance to my first performance in 2016 and a first practice in 2017, I knew that he has strong engineering skills. So I managed to get his very good code review for my practice this time.

Algorithm analysis

Here is my analysis of the algorithm. I like to present here. Since I wrote the code based on the idea presented in the analysis, the peer advised me to change the design, do not define the substring variable (line 31) and get the substring all the time; and the concern of heap usage to store C# reference variables. Only last line of code to return substring using slide window left pointer value and substring length (line 40).

I spent extra a few minutes to explain the time complexity of the algorithm, since we are doing iteration of the string once, and then each sliding window we are not recounting all the chars to see if the substring is found or not, a variable is maintained to keep check. So the time complexity is optimal. It should be around O(n), since left pointer of slide window at most visit each char in the search string once, same as right pointer of slide window.

Code review  

Here is my code to pass all test cases, I spent around 40 minutes to explain the algorithm and write the code for the idea. Since the peer had not worked on the problem before, I spent extra time to go over the idea and explain my analysis and design of the algorithm.

I spent extra 5 minutes to find the bug and then make sure that dictionary variable is filled with all keys.

My code with a bug I did not catch through my whiteboard testing, run tests button catches it:
    var dictionary = new Dictionary<char, int>();
    keys.ToDictionary(key => key, val => 1);

Should be:
Line 14:  var dictionary = keys.ToDictionary(key => key, val => 1);

Since the peer has more experience on LINQ than I do, he is very helpful to give some explanation how to construct the key and value using LINQ. Need to look up Lamda expression keyword later on.

The above code a few places are reviewed by the peer for improvements.

line 50 - the peer advised me first to move the code to if block to avoid extra work, string usually takes some heap space. Later the peer advised me to remove the variable.

line 52 - the bool variable is not necessary

line 60 - add ++ after var leftChar = search[left++]; so line 71 can be removed.
line 64 and line 65 merges to one line.

Here is the code after the peer gave me the code review. I will document each review the peer gave to me, and some explanation.

No need to store substring

I like to present a diagram about the code review I got.

Code with modification

Here is the code after the modification by the peer for the above section.

Best peer for the Saturday January 13, 2018

January 14, 2018


I had 6 mock interview in the day of January 13, 2018. Right now I have two candidates, I could not decide which one is the best peer. How can I make a sound judgement call?

Let the story begin.

The first candidate did not give me response. 12:00 PM one. The second candidate gave me review, here is part of the review.

I used to get a lot of complaints about the communication. This one also has a smell about it.

Here is another candidate, I learn how to developer web front end and what to learn:


Root of a number

January 14, 2018


It is such a great machine learning algorithm on mock interview platform. I spent 50 minutes with a top ranking university with highest GPA, a master student to work on a problem solving. Quickly in less than 20 minutes the solution was written and also pass almost all test cases. I was amazed by the peer the engineering power, the way he tested the code, and the quick he applied to small increment value from 0.001 to 0.0009 to 0.0001, and also the answer he gave to me why it is good idea to always increment or decrement one value.

I have worked on the algorithm through mock interview near 10 times, I never came cross this idea to apply increment/ decrement the middle value one but just simply apply the value from 0.001 to 0.0001.

Code review

Here is the code written by the peer using C++. I like to code review later on.

Leetcode 10: regular expression matching

January 14, 2018


It is so surprising that I met such a great master student from California and he also encouraged me to write a dynamic programming solution for Leetcode 10: regular expression matching. The peer is also very good to help me to understand b* pattern how to apply zero time, one time or more than one time. The peer looked at my analysis of logic and asked me to optimize to skip last char * if applying once. It is the first time I understood the idea after I struggled so long, the peer told me in person.

Learning is so much fun, specially when the peer is top ranking master graduate student with a lot of good intern experience, and also good research ability. I can tell the big difference from other graduate students with less practice on Leetcode algorithm.

Code review

My C# code was written in less than 30 minutes. The code has a bug to pass the test case "" with pattern string "b*". I need to work on base case when the text string is empty, it still can match pattern "b*" or "b*a*" etc.

Please study this version of dynamic programming code and then fix the bug in my C# code. Please work hard as the young graduate Chinese student does, here is the blog.

Follow up

The code is fixed and now it works for all test case. C# code is here.

Saturday, January 13, 2018

React route course

January 13, 2018


It is so busy that I do not have time to do research by myself what front end technology I should adopt and then apply to my work. Since I have very good performance on mock interview, today after the mock interview, the peer shared with me his experience to learn front end technology.

React route course

Plan to spend some time to look into those courses. Here is the link.

Frontend Masters - Learn JavaScript for WordPress using the WordPress REST API

January 13, 2018


I met a JavaScript front end developer on mock interview platform, through extra algorithm discussion after mock interview, the peer was so happy that he shared with me some advice what to learn in terms of front end development of website.

One of his advice is to learn courses from frontend masters. I have chance to look into this course: Learn JavaScript for WordPress using the WordPress REST API.

JavaScript is my next goal

January 13, 2018


It is so exciting to plan what to work on in 2018. Finally I should have time to learn some technologies besides mock interview, algorithm and data structure practice. Since I practice mock interview, I learn that the issue I have is to relax and perform on mock interview, but in theory those algorithm and data structure problem I should have solved them, or I believe that I can learn and solve it quickly.

JavaScript and technology

Today the peer shared with me what to learn in terms of react framework, and recommend me to learn from those websites.

Ruby on Rails
Node.js (express.js koa.js)

React / redux ++++
Angular 2 / 4

One humor a day

January 13, 2018

Have you read a story about one humor a day, live life to 99 years old. Today I will share you with a funny story about numbers.

Through mock interviews, I keep meeting new people. But also I make mistakes on living cost and salaries.

Today story is about the mistake I asked to the peer about $12,000 US dollars. Let us call it $12,000.

$12,000 story

I hear a lot of stories about startup in California, United States. Back in 2014 I went to California Milpitas and visited my elder sister, I also spent over 5 days vacation in California.

Today I was told that the peer makes around $12,000. I thought that he is getting $12,000 annually, and he complained to me that the rent is expensive, almost $1200/ month. And I think that how smart the startup can pay a good employee like that these days, $1000/ month for an intern price.

Actually it is $12,000 x 12 annual salary. 

Algorithm and friendship through mock interview

January 13, 2018


Life is so busy and we have so many problems to work on. I have to work on my sponsor application project, I like to talk to my nephew for his principle application, but he does not want to take my phone call or wechat. I have to learn so many things, go to swimming, take some courses, and work on other things like my mortgage loan search, and other things like going out and enjoying the friendship etc.

I spent this Saturday with most of time to practice mock interview. Starting from 10:00 AM, 12:00 PM, 4:00 PM. Before it is so rare that I can meet one person who talked to me about algorithm and data structure, it only happened twice or thrice from 2010 to 2015. One hour a year from Microsoft employee. But since last March 2017, after I started to practice mock interview, I gained confidence to meet a programmer a day, I had so much experience to work with different programmers, from senior developer, leaders, managers, graduate student and undergraduate students. Every hour a time, I have met over 150 programmers over last 10 months.


Through mock interview, I have worked with more than twenty Indian students or programmers now. I am pretty sure that it is very easy to work with Indians. Definitely I can get along and I can work with them easily.

I could not believe that I have learned so many things from Indian. Before March 2017, I never had chance to sit down with an Indian to talk over an hour. But now I have learned so many things through mock interview those 20 + hours.


Now it is so easy to get connected to Chinese. I have met so many graduate students in USA and Canada. I almost interviewed over ten top 100 ranking university students.

Today it is the first time I met a Chinese who likes to talk to me over one hour and 45 minutes, also works full time in a startup in California. I asked the extra algorithm for him to solve, and then he found that the problem was so interesting. I kept telling him that I will not give any hint. But he solved the problem pretty quickly.

We do discuss some math problem, how to define the possible brute force solution for maximum number of chunks. I argued that the first chunk starts from index = 0, one option only. But the end index of first chunk can be 0, 1, 2, to N - 1, N options. So brute force gives N options first chunk. We at most have N chunks, so brute force solution's time complexity is O(N * N). This gives the peer hint and he quickly came out the solution.

Startup, Microsoft and Googler

It is not big surprise for me to meet a peer on mock interview platform who works for Microsoft and has Google onsite interview experience today, I learn how other people work and how good people are to solve algorithm and data structure problems. I have met more than five Microsoft employees since last December.

Through mock interview practice, I learn how to connect to people and also learn from each of them.

Root of a number

January 13, 2018


It is so interesting to meet an engineer and I can compare to the peer's performance. What we discussed in the mock interview at the very beginning is about lower bound and upper bound. For example, given x = 7, n = 3, how to define an upper and lower bound fitting for most of x >=0 and n >0 as integer?

We have to define it to apply two case, one is x < 1 and x > 1. The good range is [0, Math.min(1, x)]. The thing I can learn from the peer is the way the peer communicates, and how easy he is to be able to communicate. That is something I can learn.

Of course the peer has not practiced the algorithm over ten times in last six months as I do. But let us look at his code and see how good it is.

Code review 

Here is the C# code.

One algorithm is tagged #好玩?

January 13, 2018


It is the first time I tag the algorithm using Chinese word 好玩. I met the peer through the mock interview and I spent over 30 minutes time to discuss the solution with him. At the end of the discussion, he said that word in Chinese 好玩. Both of us worked on mathematics major, the peer works for a startup in California, and I work in the city Vancouver, Canada.

It is very good time to coach each other after 50 minutes mock interview. I asked the peer to solve the algorithm called maximum number of chunks.

Algorithm discussion

Here is the transcript for our discussion. The final result is that both of us are very happy. I like to measure how good the peer can think and analyze the problem, he did so well, and then he came out a simple formula for the solution.

At the very beginning, I presented the problem statement. And then the peer asked me can you give more examples?

So what I did is to add more examples. And then we discussed the brute force solution. What is maximum number of first chunk options.

First chunk always starts from index equal to zero, but the end value can be index value 0 to N - 1. The peer came out the checking of running sum equals to the expected sum of ( 1 + 2 +...+ index).

Leetcode: Array of Array products

January 13, 2018


It is the time for me to write Array of array products again. Last two practices, I made some mistakes. One time I made 3 mistakes in Dec. 2017, I documented in the blog. So this time I have to work on something to make it perfect. What I did is to count how many multiplication I have to allow me to consume in the design of dynamic programming method.

Code review

Here is C# code.

I wrote down the multiplication allowed in first iteration from left to right, I only allow myself to do n multiplication. However, second iteration from right to left, I have to do one more extra multiplication, take the existing product value to multiple rightToLeftProduct variable.

This time I did extra work to check how many multiplication operations are allowed in the design process, I write perfect code based on this extra checking.

After the mock interview, I asked the peer to solve extra algorithm related to DFS and dynamic programming method.

Actionable Items

January 14, 2018 11:33 PM

Julia, try to work on your analysis. Make your writing a better one. Think about production ready code. Also think about analysis of algorithm should be ready to publish as well.

Learn from the peer how he wrote his analysis algorithm. The blog is here.

JavaScript: Largest smaller binary search tree key

January 13, 2018


I do not have time to write a lot of JavaScript code last 12 months, since most of time I have to write C# code. But this morning 12:00 pm I had a mock interview, I met a programmer and then he showed me how to solve the problem using JavaScript.

Code review

Here is JavaScript code with his code from line 26 to 59. The peer came out the recursive solution and then base case correctly, and only comment I had is to clean up code, avoid duplicate node.right on line 46 and 51.

Since the peer solves the problem in 20 minutes, I told him that I will start my algorithm. After I complete the algorithm, I will ask him an extra algorithm problem.

Get minimum path sum of Root to leaf path in a tree

January 13, 2018


It is my turn to write a tree recursive solution called minimum value of all path sum, for each path root to leaf node in a tree. I have already practiced multiple times, this time I spent first 15 minutes to write down my analysis.

Analysis of algorithm

It is the first time I have time to carefully go over each step and write down the analysis. This only happens after I master the recursive function using the template.

First of all I write down all the paths from root to leaf node first, and add the sum for each path. And I give a title called "Go over all the paths". Next I write down "Find minimum value". Third I write down my depth first search using recursive method. I write my template for recursive solution.

Here is my analysis of the algorithm:

Code review

Here is my C# code.

10 minutes talk about my mock interview experience

January 13, 2018


It is time again for me to share my experience after mock interview today. I spent 10 minutes to share my advice, but I like to write them down, so I can serve better for future mock interview. If I am asked to give some advice, specially those just graduating from master degree of computer science, and do not have time to practice a lot of Leetcode algorithms.

Questions and answers

Q: What advice do you have?

Do not get frustrated. It takes some time to get used to do mock interview. Relax, later on you will forget what matters to you now. Do not quit practicing mock interview.

I quit to practice mock interview in 2016 after less than 2 months, less than 10 mock interviews. I did not admit it, but it must be frustration, low rating, I think that I will get back to work on after I practice more by myself first.

I came back to practice mock interview again March 2017. I failed 30% of first round mock interview. Face the reality, and work on those algorithms and data structure.

Do not quit until you get right. Work on algorithm, I apply the principle "Do not quit until you cannot get it wrong". It is smart to work on mock interview again and again on those algorithms.

Q: What to do in order to improve the problem solving?

Work on some coding styles before you work on Leetcode algorithms. I choose to work on code review on

Q: How many mock interview have you completed?

I have completed more than 150 mock interview since March 2017.

General advice:

Find all possible strings

January 13, 2018


It is my favorite algorithm to write a combination of string "abc". There are eight possible combination, each char with lower case in original string can be lower case or upper case in combinations.

Code study

Here is my code.

A recursion tree

Let me draw a recursion tree to illustrate the problem. The peer and I had some discussion, and the peer told me that there is need for memorization, using dynamic programming. I was not so sure in mock interview, but now 12:18 AM, 1/13/2018, I am pretty sure that no need to do memoization


Total combinations are "abc", "abC", "aBc", "aBC", "Abc", "AbC", "ABc", "ABC"

Largest smaller binary search key algorithm

January 13, 2018


It is time for me to write my favorite algorithm called largest smaller binary search key. I made so many mistakes on the analysis of the algorithm, today it is the first time I wrote the binary search tree inorder traversal result first, and then went over the sequence to illustrate how to find the largest smaller binary search tree key.

Code study

I like to work on the improvement how to write down very good analysis of the algorithm. At least I know the importance to write down inorder sequence matching binary search tree example, and then use the example to explain my understanding to the peer. And then try a few more examples on the sequence and develop coding strategies.

It is true that I know the weakness of my analysis on this algorithm.

Here is C# code with analysis. The mock interview was 10:00 PM Nov. 12, 2018.

Friday, January 12, 2018

Leetcode 76: Minimum Windows Substring

January 12, 2018


It is time for me to do some code practice besides reading my favorite article called Leetcode pattern 2 sliding window for strings. I like to go over each algorithm and study code first, and write C# code later on.

It is so excited to learn that the young student wrote such a great article to expedite my learning process.

Code study

Leetcode 102: Binary Tree Level Order Traversal

January 12, 2018


I have not write code using queue for a while, so I have some concern about my skills using C# Queue class. It is good for me to go over some discussion panel related to Leetcode 102: Binary Tree Level Order Traversal.

Plan to review the algorithm Leetcode 102: Binary tree level order traversal.

Leetcode 150: Evaluate Reverse Polish Notation

January 12, 2018

Plan to review the algorithm Leetcode 150: Evaluate Reverse Polish Notation. Read as many discussion as possible. The discussion panel is here.

Wednesday, January 10, 2018

Leetcode pattern 1: DFS + BFS

January 10, 2018

Plan to read the medium article called Leetcode Pattern 1 | DFS + BFS == 25% of the problems - part 2. The link is here.

Leetcode Pattern 2 | sliding windows for strings

January 10, 2018


It is so nice to get connected to the peer after the mock interview, so I had chance to check the peer's like on and then I found very good articles to read. The biggest achievement of today, I know one more programmer and also a blog writer, Sourab Reddy, a google intern in 2017.

Leetcode pattern 2: Sliding windows for strings

Plan to read this blog.

Leetcode Patterns

January 10, 2018


I just had 10:00 PM mock interview today, and then I had chance to talk more to the peer after one hour. Basically what I shared was that in 2016 I started to practice mock interview from March, and I ended practice some time in April 2016. I only practiced less than 10 times. I did tell the peer that do not feel frustrated, once you get comfortable on mock interview, you will perform much better. I already practice over 100 mock interviews, I stopped in April 2016 since I felt frustrated, I did not admit it but it is true. I thought that it is better to wait until I practice more on algorithm. I came back to practice mock interview after March 2017, and my first round of mock interview I failed at least 20 - 30% of algorithms.

I also had chance to read one of Google intern's blogs on medium since I got connected to the peer. It is the small world, very exciting to learn something through the blog.

City and Fireman Vincent

January 10, 2018

Plan to work on the algorithm called City and Fireman Vincent. It is the first medium level algorithm on related to disjoint data structure.

City and Flood

January 10, 2018

Plan to work on the algorithm called City and Flood.

Owl Fight

January 10, 2018

Plan to work on the algorithm called Owl Fight.

Teacher's Dilemma

January 10, 2018

Plan to work on the teacher's dilemma.

Count friends

January 10, 2018

Plan to write code for the algorithm called Count friends. I like to practice more on disjoint data structure, and I like to start from easy level algorithm first.

Monk missing home

January 10, 2018


It is hard to manage myself to learn disjoint set. I did read the tutorial over 6 months ago, but I failed to perform in Leetcode 684: redundant connection on January 8, 2018. One of drills I came out is to work on hard level algorithm on hackerearth this time, so I learn more through the practice.

Plan to work on the algorithm called Monk missing home.

Basics of disjoint data structures tutorial

January 10, 2018


It is a good idea to study the tutorial called basics of disjoint data structure tutorial. This time I will do better, and I will study 3 to 5 algorithm related to the disjoint data structure on hackereartch as well.

Tuesday, January 9, 2018

Disjoint Set Union (Union Find) on

January 9, 2018


Life is too busy and then I have spent over 10 times to practice one algorithm through mock interview platform called regular expression matching last 9 months. What I have learned through this hard level algorithm is to be super patient, love the algorithm called recursive solution, and then get to know more people through this algorithm. Every learning opportunity to work on the algorithm in mock interview has been documented and I just know that it is not easy at all to master one hard level algorithm. My peers of the algorithm are people with various background, different understanding of the algorithm, work on different programming language.

I like to apply the experience to a new algorithm called union find algorithm. After I blogged my mock interview of redundant connection algorithm on January 8, 2018, I choose to study more about the algorithm.

I like to ask basic questions about union find algorithm, what is union? why it is called union find? Why it is not called depth first search find? I like to learn the algorithm again, from basics first.

Here is the tutorial I like to study.

Union find lecture note study

January 9, 2018


It is always best time in the day to read some algorithm lecture notes. I just wonder what is best thing to do celebration of new year 2018, maybe the lecture note of union find is good thing to start. There are around 49 pages, I like to write down some notes and put together a nice blog with some good understanding of the algorithm.

Lecture note

Here is the lecture note.

Algorithm and friendship in 2018

January 9, 2018


It is most challenging time for a lot of people, specially for those young graduate students who studies in United States. I have met over three Chinese master graduate students last few months on mock interview platform, and I really like to work with them. It is hard for young people to find time to work on practice since they have so many courses to study full time, but somehow they can write very beautiful code also good analysis of the algorithm.

One of my most favorite is to write solution in five minutes as long as I give him the hint. I could not be more happy if I work with him as full time job. And then I will be a lazy lady and have a lot of time to learn fancy technology and framework.

Code practice

One algorithm can make friendship better because we all like to work on algorithm and data structure. So I have to write one algorithm for friendship since the peer asked me to write through wechat.

Here is my code practice today, it takes me over 20 minutes. I still made a few mistakes in first writing, and I kept telling myself "Do not use debug. Use whiteboard testing." I did and found a few bugs. And the code passed three test cases first time.

Extended algorithm

What if the elements in the array are any value?

My first idea is to sort the array, and then find the value in the sorted array using binary search, or using hashmap to record the value and its index value. But time complexity is at least O(nlogn).

The peer told me that it should be linear algorithm. So I think about it carefully, in theory we do not need to sort the array, all we care about is the first chunk max value is smaller than next chunk's smallest value.

The idea is to use extra array and then preprocess the array from right to left, and get the minimum value for each index covering the range of [index, length - 1].


January 9, 2018


I learn from my college classmates in class of 70141 of Shanghai Jiaotong University. Write down every word the teacher says in the lecture, that is long time ago, from 1984 to 1988. We have 7 girls in class of 70141, and some of girls worked so hard to learn mathematics and one of good habit was to discuss home work together before the light turned off in the evening. At that time I do not know how hard it is to write down clean notes after each class.

I like to spend at least 30 minutes to write down the notes about this union find algorithm written in Chinese. The blog is here.

Learn union find

The most challenge question is to take notes from this Chinese blog about union-find algorithm.

First let me learn take down some notes in Chinese.

Dynamic connected - 动态连通性
Union-Find - 并查集

How to model the problems? -  对问题建模

There are two solutions. One is to find path in between, using DFS algorithm. The second one is no need to find path in between, using union find algorithm. 


for( int i = 0; i < size; i++)
  id[i] = i; 


My own notes

Now it is 9:12 PM, January 11, 2018. I like to write down notes by myself this time. Through the study, I can tell the difference between quick-find algorithm and quick-union algorithm.

Quick-find algorithm, C# class is here.
Quick-union algorithm, C# class is here.
Understand what is quick in quick-union algorithm:

Root of a number in python

January 8, 2018


It is so interesting to learn to be an interviewer on mock interview. I had the conversation with the peer, and I shared my opinion that the mock interview should be a conversation. But the peer told me that it is not, and I got complaint about giving hints without being asked.

Code review

Here is python code of root of a number. Perfect performance.

Monday, January 8, 2018

Leetcode 684: redundant connection

January 8, 2018


It is another 10:00 PM mock interview. I asked the peer to give me another algorithm for interview, and he gave me the algorithm Leetcode 684.

Algorithm analysis

It is very good discussion between two peers. I shared the transcript here.

Here are the search results of union find practice in my past 12 months. I have practiced over 6 times union-find algorithm on Hackerrank.

Mock interview

Mock interview can be such a good activity, I thought about hiring a tutor met on mock platform, and then sent messages and talked to a few Chinese graduate student met on mock platform, none of them showed the interest. I know that I am out of date on this tutoring idea.

So I just go for the mock interview, if I meet a strong talented peer, just ask the peer to give me a tough algorithm to work on. The peer chose this one and it is the medium level. After the mock interview, I went to bathroom and looked at mirror, I almost cried since I felt that a drop of tear came out. Life is tough, mock interview is tougher than hackerrank contests. You have to push yourself to understand the algorithm, ask good questions, and then argue to myself to define the problem related to the given example, solve a well-defined simple problem. This algorithm can be solved with the experience of the union find algorithm. I do have over 10 times to work on the union find algorithm last 12 months by tracking coding blog, I played contest, asked code review called value of friendship, and practiced to write C# code, but I still miss the important part, solve the problem and present to the peer.

In my mock interview, I read the problem statement loud, 2 or 3 times, in order to understand the requirement, and then I told the peer that the graph has a cycle, we have to determine if there is a cycle. Usually the depth first search can be conducted to explore the graph.

We can go over any node and then start from it to do depth first search and determine if there is a cycle. One thing is to go back to the root node.

After 10 -15 minutes discussion, I told the peer that depth first search may not be necessary, I saw that the algorithm can be solved just using hashset or hashmap.

My personality

Definitely I have some personality, and then I have to figure out what to do with it and make most from own personality. One thing I noticed is the pressure from the peer. Usually the programmer working in silicon valley has more pressure, the peer may prepare onsite interview of tier 1 companies. It is hard to be the peer and relax all the time.

One thing I like to do is to review the Chinese blog about union find algorithm, and write down notes, and write an English version blog. I really find the blog author is such a good writer and work hard to present nice and rich graph to explain the algorithm.

I could not tell the quick find and union find difference right away. And also my mock interview algorithm does not require me to work on edges in detail, just need to check if it is in the graph or not. I tight the constraints to make my problem hard to solve.

Here is the blog about union find algorithm.

Quora post

The things to work on from a facebook recruiter answer. The link is here.

Leetcode contest 53

January 9, 2018

Plan to study Leetcode weekly contest 53. Here is the link.

Leetcode 691 Stickers to Spell Word (hard level)

January 8, 2018


How to make the first month of the year 2018 more exciting? I thought about the ideas to make every day exciting and also a little tough. Any good idea? A hard level algorithm from Leetcode is a good start.

It is easy to plan to have mock interview and work on the algorithm with the peer. I am learning from every peer I meet and also learn how to work hard to help the peer learn something with me through mock interview.

In order to prepare for mock interview every week day 10:00 PM, I need to study some new algorithm as well.

Algorithm study

I understand that it takes months to learn a hard level algorithm very well on So I am planning to work on a new hard level algorithm, once I have chance, I can discuss with the peer after mock interview.

Here is the blog I plan to study starting from tonight.

Swimming in the morning

January 8, 2018


It is hard for me to take a break and go for swimming this evening, I originally plan to go to swim in renfrew park pool at 8:00 PM and then come back before 9:30 PM to prepare 10:00 PM mock interview.

I just quickly wrote a few blogs to document my algorithm practice through mock interviews, but I spent almost one hour from 7:30 pm to 8:27 pm.  So I looked up the pool hours, 6:00 am - 9:30 pm, I should go to bed early and get up early, build a routine to go to swimming in the morning instead.

Morning swimming

Plan to do some research how to build a good habit to swim in the morning.

Array of Array products

January 8, 2018


In order to master one algorithm, I have to interview the algorithm and learn from the peer. The peer told me that he is preparing facebook onsite interview, I have to learn how fast he can solve the problem.

Code review 

Here is C++ code.

One algorithm 3 solutions

January 8, 2018


It is less challenge to work on algorithm in mock interview since I already have practiced over five round. So at least I have solved the same algorithm over 5 times. I had to solve the algorithm called pair with difference, but the problem solving has no difference. I could not memorize anything, I read the problem again, and then think about the ideas, and then explain first two ideas, using hashtable, using binary search.

Algorithm practice

The peer asked me to solve the algorithm using binary search first. After I finished the binary search to solve the algorithm, the peer told me that there is another solution using O(n) time to find pair after sorting. So I wrote two pointer techniques as well.

Here is the code using O(n) time to find pair after sorting. Here is the solution to use binary search.

Learning LINQ is kind of sour

January 8, 2018


It is hard for me to learn LINQ and practice some algorithm. So I decided to write the code using LINQ in 10:00 PM mock interivew on January 7, 2018.

I also found that it is hard for me to write a working solution in less than 30 minutes.

Code review

Here is the code I wrote in mock interview. There are a few of issues. I will continue to work on later.

Mock interview should be a conversation

January 8, 2018


Mock interview should be a conversation between two programmers. Both of them are exchanging ideas and try to sort out what kind of problem the peer has to solve. I learn to explain the problem when I find the peer kind of stuck, and help the peer understand the step 2 number in this encryption/ decryption algorithm.

It is my luck to meet an undergraduate student and she worked very hard on mock interview. Therefore I had chance to discuss with the peer what is the step 2 number and how we can do reverse calculation based on encryption steps.

Code review

Here is the C++ code with the analysis. I like to review analysis part, and figure out how good the peer is. Since I know that peer wrote perfect solution after the discussion, I knew that I did a good job to help the peer understand the problem through the discussion.

Leetcode 18: 4 sum

January 8, 2018


One of benefit is to learn python programming language when I take mock interview. Recently I met a few of peers used python to write code. 4 sum is the algorithm I have practiced over and over again, but to review python code is kind of challenge.

Code review

Here is the python code. The peer and I had a short discussion how to make the code look more clean. And then the code was changed and brought back a bug.


January 8, 2018


The algorithm related to two intervals is to define the overlap area. The interval overlap is easy to define if using maximum of two start value and minimum of two end value of two intervals. I wrote another one in 25 minutes, and then I like to review the code.

Code review

Here is the C# code.

Deletion distance

January 8, 2018


Dynamic programming is most challenge solution I feel right now. Also it is very easy to write since I chose to write in bottom-up approach. The recurrence formula is still the same as the recursive solution.

It is another mock interview on January 7, 2018, 8:00 PM. I chose to use dynamic programming to implement the deletion distance. It is the first time I tried to write one in mock interview, most of time I wrote recursive solution instead. I was so excited to have some one watch me and give me constant feedback while I worked on the solution.

Code review

Here is my C# implementation of deletion distance. I spent around 25 minutes to write the algorithm including the analysis of algorithm.

Sunday, January 7, 2018

Leetcode 315: Count of smaller number after self

January 7, 2018


I had a mock interview at 8:00 PM, and then I had chance to learn from the peer. He shared me his practice using python language, and he told me that he studied one of leetcode discussion.

Code review 

Plan to study python code. The link is here.

Smallest substring containing keys

January 7, 2018


It is the great learning opportunity in Sunday morning. I spent 40 minutes to work with the peer on her first time to solve smallest substring containing all characters. I learn from the peer to work on the solution, the peer solved the problem to pass all test cases with my help. Even though the time complexity can be improved.

Code review

Here is the C++ code the peer wrote and I like to review the code later on.

Here is the gist I wrote for the analysis of time complexity and I explained the issue using an example.

Highlights of my review on mock interview:

1. line 20 - 22, I made the suggestion to group all three int variables declaration together.
2. line 26, I found the bug to add head <= runner instead of head < runner
3. line 27, I advise the peer to extract a variable currentChar to avoid duplication code
4. I added extra line on line 35 and a few other places
5. I argued with the peer the idea of runner = head -1 on line 42 and then I understood her idea, because she likes to offset +1 on line 47
6. I added line 47 for the peer
7. I told the peer that I like to review the code before she likes to run the code, so I can make the changes from item 1 to item 6.

Sudoku solver

January 7, 2018


It is another mock interview, Sunday 10:00 AM. I had the chance to work on sudoku solver, and then I spend 30 minutes exactly to solve the problem, first few minutes to explain the problem, my solution, and then I wrote the code and pass all test cases.

Code review

Here is my C# code.

Saturday, January 6, 2018

Leetcode 315: Count of Smaller Numbers After Self

January 6, 2018


It is the hard level algorithm and I am still working on the problem solving. Today after 4:00 PM mock interview, I asked the peer how to solve the algorithm. Since the peer is preparing Google onsite next month, I like to test how good he is in terms of algorithm analysis.

We had discussion around 10 - 15 minutes on the algorithm. We brainstorm the algorithm, since I worked on the algorithm more than 2 hours before, and he told me that this is the first time for him to work on the algorithm.

We discussed array, sorting, sorting to keep the index value, and then I talked about the preprocessing the data into a binary search tree. And then the peer told me to look into binary index tree, and then the discussion went on with understanding the binary index tree.

Learning python through mock interview

January 6, 2017


It is a busy day with multiple mock interviews, 10:00 AM, 12:00 PM, 4:00 PM, 8:00PM. My mock interview 8:00 PM is such a challenging one. I watched how the peer worked on python code and I enjoyed learning of python through the peer's problem solving.

It is like sitting in classroom, the peer asked me a few times about the algorithm, I had to read the python code and then figure out an answer.


Here is the Python code written by the peer to draw H-Tree. I had to learn how python language is used to construct the object and then I thought that one day I will learn a language through mock interview. The peer surprised me with the patience and very good communication skills.

Find smallest substring containing keys

January 6, 2017


It is another 8:00 PM interview and I had to work on the algorithm called "Find smallest substring containing keys". I have worked on the algorithm over five times last nine month, on my last mock interview the peer helped me and advised me to change my idea to slide left pointer of sliding window.

Here are blogs related to search results using keyword: smallest substring in my coding blog.

Here are last few practices:

Oct 28, 2017 practice is here.

Dec. 2, 2017 practice is here.

Code review 

The peer helped me through the whole process, I spent over 38 minutes to write code, pass all test cases except one. Here is the code.

Follow up

Now it is 10:50 PM, I used Visual Studio to debug the code and found the bug. On line 52, left < i should left <= i since one char should not excluded as a substring. The start and end position are the same index value.

I do not need to use HashSet to check if the char is one of keys, seen line 17, I can just use dictionary.ContainsKey(visit) to find out, seen line 30. I looked up my last practice and it is the advice from my peer back in Dec. 2017.

Feedback from the peer

It is very hard algorithm for me to work on in mock interview, but with the peer's help, I managed to find bugs early and continued to write and completed the code.

Here is the feedback.

Editorial notes

Programming is such a fun activity for me now. At least today January 6, 2018 I had so much fun to work with best talent programmers in the world.

Every mock interview is so surprising. The first one I was surprised to work with a peer, he taught me how to write a spiral matrix print, and then we exchanged the experience about algorithm problem solving related to same tree and median of stream. The second one was more surprising, because this one told me that he will work on Google onsite interview next month. The third one was even more surprising, I was busy learning python to follow the peer's problem solving, and then peer told me that she is M.I.T. computer science graduate.

How difficult is it to work on algorithm and data structure problem solving? I have worked on the hard level algorithm to find smallest substring so many times, and then I finally understood that how long it takes me to master an algorithm. It takes me 3 years to fully master the algorithm.

Today every step the peer worked me through the code and asked me questions, meanwhile I explained to the peer what I tried to work on, I even copied the analysis and then said that I do not know what to do, just make sure the test case will work for first three chars, and then go over each char through whiteboard testing.

How patient I will be when I write code in daily work, can I write production ready code every day starting from January 8, 2018? Do I need to write hard level code like this one "Find smallest substring containing keys" every day?

The mock interview experience just brought the whole world to me. I sit in the home office whole day and continuously work on the algorithm, exchange the tips to solve the problem.

I know that programmer life should be easy once I master the skill to work with smart people, open and share the ideas.