Monday, January 8, 2018

One algorithm 3 solutions

January 8, 2018

Introduction


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

Introduction


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

Introduction


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

Introduction


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.


Interval algorithm

January 8, 2018

Introduction


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

Introduction


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

Introduction


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

Introduction


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

Introduction


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

Introduction


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

Introduction


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.

Python 


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

Introduction


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.

Find smallest missing nonegative number

January 6, 2018

Introduction


I had a mock interview 12:00 PM. As a programmer I cannot tell the peer is an excellent programmer until the peer wrote one line of code but I could not understand. So I asked the peer what is the meaning to turn the positive number to negative number, and the peer told me that he likes to mark the index is found.

I have practiced this algorithm over 5 times, but I never came cross this idea.

Code review


Here is C++ code for the algorithm.

My last practice in Nov., 2017 is here.

Binary search tree inorder successor

January 6, 2018

Introduction


I met a peer on 12:00 PM mock interview. We discussed the algorithm and then the peer wrote some code.

Here is the transcript. The peer told me that he is working on this February Google onsite interview, when I gave appraise his code for the algorithm. He wrote in less than 10 minutes after I gave the hint about recursive solution. He said that he liked to write an iterative one.

Make it more readable



One thing I did very good as an interviewer is to put the drawing inside sharecode.io, and also write down the inorder traversal of tree, mark the root node and also using g to mark given node position, first case is the same as root node, second one is the right side of root node, and the third one is left side of root node.

The whole presentation of the problem is much more readable and easy to work on. I am becoming more experience to give the peer an interview.

Now it is 7:46 PM, and I like to upload the link with more readable problem statement on github for this binary search tree inorder successor. Here is the link.

Same tree

January 6, 2018

Introduction


It is so relax and enjoyable to experience the discussion of same tree algorithm. One of mock interview activity is to coach each other if having chance.

After today's 10:00 AM mock interview, I also had chance to exchange the idea to solve algorithm problems. The peer shared his experience with same tree algorithm, similar to Leetcode: Same Tree easy level one, but the tree can have multiple children. And I shared the algorithm about median of stream. The peer saw the problem before and he knew that the max and min heap are useful.




binary search tree inorder successor

January 6, 2018

Introduction


It is very exciting time to meet a peer on mock interview. After the peer solved the problem perfectly, I asked to give him another algorithm to solve. Because I like to evaluate how good he is and also learn the algorithm through the discussion. Keep it a secret, I also like to develop the skills to evaluate the candidate technical strength on recursive solution.

So today after 10:00 AM mock interview, I asked the peer to solve the binary search tree inorder successor.

Usually what I did is to go to the above code review link, and get the binary search tree image url first, and then open a page on codeshare. I put together the problem statement with tree node data structure, the function definition with two arguments.


Peer discussion


Here is the transcript for our discussion. The peer chose to use the idea to write an inorder traversal of the tree using recursive function, and then piggyback the idea to check if the given node is found. Next visit should be the successor.

The discussion between the two peers are related where to put the successor checking. My argument is to put at the beginning of the function, and then peer likes to put else clause. I expressed the concern of a bug to write this way.

Later the peer told me that the search is O(n) time complexity where n is the size of the tree. The optimal solution can be better, O(logn).





Matrix spiral print algorithm

January 6, 2018

Introduction


It is another 10:00 AM mock interview. The peer worked on the algorithm called the matrix spiral print algorithm. So surprisingly, I learned a new way to write the solution and also the code is much simple and easy to follow.


Code study


Here is C++ code to pass all test cases.

It is so interesting to read the blog I write back in March 2016, the first time I practiced the same algorithm on mock interview platform. At that time, I was so shy and the code I wrote was not so clean and readable. And I even read the code I wrote back to 2015.




Linear scan algorithm

January 6, 2018

Introduction


I had a mock interview 10:00 AM and the algorithm is to find the duplicate. I only wrote the code for one of two cases, using linear scan algorithm.

Code review


Here is C# code. The peer asked me what is LINQ, so I spent a few minutes to find the stackoverflow post and shared him the solution to use IEnumerable.ToArray().


Leetcode 18: 4 sum

January 6, 2018

Introduction


I had a mock interview at 10:00 PM in May 5, 2018. I learned some JavaScript from the peer, but also I had to learn how to help the peer write a brute force solution using JavaScript. I had to write down the four loops and then also write the start index for each loop for the peer.

Brute force four loops


It is the first time I had to show the peer how to write brute force solution using four for loops. And also it is my job to fix the start index for the peer as well.

I made the comment to remove the line beside a while loop, and then line 12 to line 15, I changed the start index to i + 1 instead of 0, likewise to apply k and l.

Code to review


Here is the JavaScript code written by the peer in JavaScript, passing all test cases on mock platform. It is also a brute force solution.

I have to learn how to help the peer write a brute force solution first, and then let the peer understand the solution and get the good feelings to solve the problem.




Get organized better

January 6, 2018

Introduction


It is the good idea to stay organized. I like to find the good coding blogs to read through my blog search. I need to add some labels for the blogs, "Algorithm blog" should be  a good name for label.

Sometimes I cannot find the good coding blog to read.


Coding blogs



  1. Imperial college of UK - coding blog written by a facebook engineer.
  2. Leetcode blogs
First one is chosen on January 8, 2018:

        Graduate student - hrwhisper blog is here.
        by subject:
       Dynamic programming

       https://www.hrwhisper.me/leetcode-algorithm-solution/

Second one is chosen on January 10, 2018:
      http://blog.csdn.net/worldwindjp

My favorite one is common mistakes in binary search algorithm. The link is here.

Dynamic programming practice

January 6, 2018

Introduction


It was another 10:00 PM mock interview. I wrote the algorithm called number of path. At first I wrote the algorithm using O(n2) space, and then I was asked about space complexity, so I noticed that the space complexity can be optimized to O(n) space.

The C# code with space O(n2) is here. And the C# code with space O(n) is here.



Thursday, January 4, 2018

One mock interview a day keeps doctor away

January 4, 2018

Introduction


It is my most favorite saying that one apple a day keeps doctor away. As a software programmer, one mock interview a day keeps the doctor away. I always find that the best time of a day is to meet a graduate or undergraduate student in top ranking university in the world, top 50. I always find that it is so easy to share and also learn from each other through algorithm and data structure problem solving.

It is the most popular pass to win a friendship using talent to write clean code and also work hard as an interviewer to help peers to analyze the algorithm. I have fully enjoyed my fifth round mock interview, I kept my score high and then I kept myself so excited to meet younger generation players. Last few days, I met a top player from Tsinghua university, a senior master graduate student of computer science, and then yesterday I met another undergraduate student of Sydney Australia UNSW university, my both mock interviewes were extended and both of us shared more discussion on algorithm and data structure problem solving.

Status report


It is another date for me to relax and write something on my blog. I thought that I did set up 10:00 PM mock interview, but I did not have any one when it was 10:00 PM. I do not know what is going on. This happened a few times already, the mock interview platform lost my appointment, I could not believe that it is true.

Here is my status report.





Skiing trip to celebrate new year 2018

January 4, 2018

Introduction


It was the first sunny day in the whole week, last day of 2017, Thursday, Dec. 30. I went to Seymour mountain to learn how to ski, and I left home around 2:20 PM. After 20 minutes driving, I took the bus in parkgate community center to the top of mountain, at 3:00 PM.

Sightseeing 


I spent first 20 to 30 minutes to walk around at the top of mountain and see the beautiful views. Here are the links on my Instagram, one is beautiful mountain view. First time I used hashtag to publish the videos and photos.

I found one of likes is very useful. I need to use those hashtag as well. As a software programmer, I need to learn how to reach out more people through social channel.

Emotions


To learn skiing, I went through so many emotions over 5 hours practice. I like to document the feelings and see if those feelings make any sense.

Learning skiing is so much fun. I went through so many emotions, fear, pain of hand after the fall, fall on snow, fall on escalator, scare of slope, laugh, quick learning.

New year resolution


I chose to spend time to work on the mock interview last week of Dec. 2017, and the last day I went out to enjoy 8 hours outdoor, 5 hours skiing and finally learned how to skiing and fully enjoyed the sports. I could not remember so many fall down on the snow, the first one and last one I remembered, and then when I deal with the pain and itching after 24 hours, I started to remember so many falls through those hours on the slope of mountain.

I like to learn from my sports activity last day of 2017. Do not stay in my comfortable zone every day. I have to learn things once I stay out of my comfortable zone. I have to learn dealing with fear, falling down, failure, taking calculated risk, and then I will learn quickly.

Being a mom may be the best opportunity for me to learn everything in my life. I miss the opportunity in my early 20s, 30s, 40s, I should learn from other people in Canada, those mom who teach themselves skiing and also learn together with their teenager son I met on the skiing trip. Remember the quote she shared, "I only watched youtube how to ski yesterday 15 minutes. You have to learn how to make left and right turn by shifting your weight to left or right." Self learner mom is also giving me the best lesson in the life.




How to get the tutoring in a bargain?

January 4, 2018

Introduction


It is the time for me to think about hiring a tutor, I met a very top performer in my mock interview so I like to plan to hire him to give me some tutoring. In order to get more training, I like to find one or two together to get the tutoring and share the cost.

For me the binary search tree inorder successor algorithm can take over one hour, the tutor only takes less than 10 minutes. I like to look into what I should ask to work on from tutoring service.


Linked list data structure

January 4, 2018

Introduction


It is best time for me to work on the algorithm and give my own understanding to the peer. Here is one of algorithms I like to look into more.

First let me document the discussion first.

Problem statement: Given two vectors which are sparse, calculate the sum of product of two array, and create a data structure.
For example, first vector [1, 0, 0, 0, 1], and second vector is [2, 0, 1, 0, 0],
and then calculate the sum of 1 * 2 + 0 * 0 + 0 * 1 + 0 * 0 + 1 * 0.

Analysis:

I like to use the single linked list to reprent the vector, each vector two single linked lists are used, one for the index value,
one for the value of itself.

For example, vector [1, 0, 0, 0, 1] can be represented by index linked list:
 0 -> 4, array length = 5

index value ->       0 -> 4
value linked list -> 1 -> 1

-> up

[2, 0, 1, 0, 0] -> 0 -> 2 , length - 5 -> million
-> down

up -> 0 1 * 2 = 2 -> sum
up -> sum + 0 = sum

Problem -> optimal structure -> merge two lists ->
0 -> 2 -> 4

[1 * 2 + 0 * 0 + 0 * 1 + 0 *0 + 1 * 0]

Binary search algorithm

January 4, 2018

Introduction


In terms of search efficiency, the binary search will be much more efficient compared to linear scan.
Last 6 months I have practiced so many binary search with so many peers, write a few blogs related to the issues I have.

After the mock interview, I have some short discussion about binary search algorithm again.

Repetitions


It is the best time for me to discuss the algorithm with the peer. Here is the algorithm.

Here is the question link.


Problem statement: Given 2 vectors with multiple repetitions, calculate dot product, and create a data structure.
For example, two vectors:   [2, 1, 1, 1] , [2, 1, 1, 1], and the dot product is [2 *2, 1* 1, 1 * 1, 1 * 1].

The peer shared his original idea to design a structure like the following:

[2,1 (a million times)]

In c, the problem can be written in the following:
typedef struct pair{
  int value;
  int amount;
}Pair;

int dotProduct(Pair v1[], Pair v2[]){
 // write this function
}


Instead I gave my thought, given start and end index of repetitive number, so binary search can be applied to do
the index search. Otherwise, the peer's data structure the array search will be linear scan.

[1, 2, 1000,000, 100,000 + 1] -> binary search ->
[(1,2), (million, 1)] <- new data structure (1, 2), (2, 1), ..., (1000,000, 1)

If the number is not in the array, just return the value next smaller or bigger index with value. 

Answer the question first

January 4, 2018

Introduction


It is another 10:00 PM mock interview, and I had chance to look into the table and answer the peer's question, how to come out the step 2 number? I looked into those numbers and then I came out the answer the first time.

Here is the code written by the peer and I like to give it a review.

Here is the pseudo code written by the peer. Such great workout. The coding is perfect, the pseudo code is also very clear. Most of important for me is to learn the algorithm itself. I have practiced this algorithm over 10 times, I still could not think about how to calculate the step 2 number, the peer asked me the question and then I started to figure out the formula in mock interview.

I can tell the difference between me and the peer. The peer is more curious to know things thoroughly. He likes to ask questions and explore, and then he is very well organized.

decrypt(word):
    output = []
    currStep2 = 1
    for enc in word:
      diff = enc = currStep2
      letter = addUntilASCII(diff)
      currStep2 += letter

Dare to compare 


Let me put together all my past practice here. And then I study and compare to the peer.

Dynamic programming practice

January 4, 2018

Introduction



I wrote a dynamic programming at 10:00 PM mock interview. I made a few mistakes after white board testing, and then I depended on the web compiler and fixed the issues.

Here is the code.


Performance issues



First one is on line 7, <= 1, not < 1; second one is related to calculate the product, line 19 and line 26. The product should include current element's value; the third one is line 25, it should keep the first dynamic programming result and then continue to add more multiplication.

Wednesday, January 3, 2018

Heap rank

January 3, 2018

Introduction



Plan to read the blog about heap rank, the link is here.

Here is the gist I created for the algorithm. It turns out that the algorithm is the great one to practice depth first search using recursive function.



I like to write a sentence to explain how to use recursive solution to solve the problem. Give the value x in the heap, start from root node and see if it is bigger than value x, if it is true, and also there is neither left or right child, then return 1; we handle the base case first, and then we ask left subtree and right subtree to solve the same problem as well.

Leetcode algorithm over 500 practice

January 3, 2017

Introduction


It is first mock interview in 2018. I had 10:00 pm mock interview, and I met a university graduate student, top ranking university. I spent two hours to work on mock interview, first 50 minutes we talked about situation, analysis and some sharing. And next 60 minutes or so I had chance to interview the peer.

Super performance


The peer has great performance. Here is the graph to show how a person can finish Leetcode algorithm over 500.



Here is the code the peer wrote, and it is the algorithm to find binary search tree inorder successor. The peer wrote iterative solution first, and then I asked a recursive solution, he wrote the recursive one in 10 minutes. He said that let me think about it, and in 1 - 2 minutes he wrote the correct solution.

Python code to write the algorithm similar to 4 sum is here.

So I have to look into the paid mock interview service market price. I have never tried before. Here is the one I like to try this year.

My performance


I was asked to merge two binary tree, and then I spent around 15 minutes to discuss and then I wrote the solution, and the peer gave me the comment to write clean code, simplify the logic.

His ideal code is here.

Monday, January 1, 2018

Listen to your friend on the tennis court

January 1, 2017

Introduction


I have met a lot of friends in Burnaby central park over the last five years. And also I met Chinese, software engineers and also realtor in part-time. I remembered more than 2 years ago one of the friends told me that I should invest in a condo, if the time I save money from the salary cannot catch up the property price goes up.

It turns out that he did good job to advise me. But I did not take his advice at that time.

So let us write a good blog this 2018 new year day, called Friends Make This World Better Place to Be.


Good Friends Everywhere





Saturday, December 30, 2017

Discussion Panel of Leetcode 72 - Edit Distance

Dec. 30, 2017

Plan to study the discussion panel of Leetcode 72 - Edit Distance.

Here is the image of top ranked discussion readings:


Edit Distance lecture notes

Dec. 30, 2017

Plan to study lecture notes again. Here is the link.


Leetcode 72: Edit Distance

Dec. 30, 2017

Plan to study the blog Edit Distance. Here is the link.

Lecture note study: Edit Distance

Dec. 30, 2017

Plan to study the lecture note about edit distance from Jeff Erickson. Here is the link.

Leetcode 72: Edit Distance

Dec. 30, 2017

Plan to study the blog related to Leetcode 72: Edit Distance.

Here is the blog link.

Wikibooks: Algorithm Implementation/ Strings/ Levenshtein distance

Dec. 30, 2017

Plan to read the wiki page about Levenshtein distance. The web link is here.


Leetcode 72: Edit the distance

Dec. 30, 2017

Introduction


Plan to watch the video about edit distance, it is titled "How to Calculate Edit Distance Between Two Strings". The video is about one hour long. Here is the link.


Leetcode 72: Edit Distance

Dec. 30, 2017

Introduction


It is the Saturday morning, I like to go out to play tennis, and it is the first day of week we have a sunny day. Also I like to review the algorithm Leetcode 72: Edit distance.

Here is the blog I like to review today, I found it through my 2015 blog.

I also created a gist for the code written by the author. Here is the link.




Friday, December 29, 2017

Leetcode 334 - Increasing Triplet Subsequences

Dec.29, 2017

Plan to study the code using this blog. 

Algorithm blog quick scan

Dec. 29, 2017

Introduction


I plan to go over all many algorithm blogs as possible for this holiday break found on the website, a graduate of Imperial College London, Rafal, R. Szymanski.


Leetcode algorithm


There are 31 algorithm in the blog, I will quickly scan the algorithm and learn something. And I will tell which one is my favorite algorithm. 3 things I like in terms of algorithm code quality, give some code review as well.

Codility

There are 15 algorithms. I will study those algorithms as well.

Project Euler

There are 5 algorithms.

Algorithm topic

There are 23 blogs for various topics.



Leetcode 10: regular expression matching

Dec. 29, 2017

Introduction


It is so interesting for me to learn Leetcode these days. I work on mock interview continuously on those 30 algorithms. And today I reviewed Leetcode 18: 4 sum last 5 practice, and then I tried to get organized and reviewed the past practice, and then found this young graduate software engineer working in facebook, I start to code review his post on each Leetcode algorithm.

Code review


Leetcode 10 algorithm blog is here.

Here is the gist I created for the study. I will play this code and write a C# and figure out how it is.

Algorithm notes

Dec. 29, 2017

Plan to read and use the algorithm notes written by a facebook engineer. Here is the link.


K Sum Problem (II)

Dec. 29, 2017

Introduction


I wrote a K sum problem in Chinese this morning, and then I found that I have to write an English one in order to get better understanding the problem. It is Friday, my free time, one week off. And I already spent over 60 minutes to improve writing in Chinese to make it more accurate, and readable. So I start to google and then find some article to read in English, I miss the very good writing with mathematical analysis.

Here is what I found. The article is called K numbers in array that sum to C. And then I checked the contact, the author is working for facebook. So I am better to spend some time to read the article, high chance the article is good one. Also the author has practice on Euler.net, 75 algorithm solved. I have not solved any problem on Euler.net yet.

K sum problem


Every good algorithm problem attracts top talented programmers. I like to read and figure out if I can have good time to learn something today. Now it is 2:43 PM, I have booked mock interview 8:00 PM, 10:00 PM. Plan to go to Ice Rink to skate and swimming, and then enjoy the rest of day with two mock interviews.



K sum problem

Dec. 29, 2017

Introduction


I spend time to get organized last 5 practice of Leetcode 18 4 sum algorithm. And then I came cross a blog written 18 months ago, and then started to read the blog.

The blog is title called "K sum problem". It is written in Chinese and the link is here.

K sum problem 


The mock interview practice is to relate to how to quickly figure out the solution and also write code in less than 30 minutes, sometimes it should take less than 20 minutes, or less than 10 minutes. The training is to focus on good understanding of the algorithm, not too much theory involved.

But I do have strong interest in the topic about time complexity. So I decide to copy and paste the Chinese writing here, and modify the content in terms of style, make it more readable. But the time I spent on is over 30 minutes now. I decide to find a good written article in English instead.

Later on do some study related to it.

k sum problem (k 个数的求和问题)

问题陈述:

在一个数组,从中找出 k 个数(每个数不能重复取。数组中同一个值有多个,可以取多个),使得和为零。
找出所有这样的组合,要求没有重复项(只要值不同即可,不要求在原数组中的 index 不同)

解法:

2 sum 用 hash table 做,可以时间 O(n),空间 O(n).
2 sum 如果用 sort 以后,在前后扫描,可以时间O(nlogn + n) = O(nlogn),空间O(1)
2 sum 用 hash table 做的好处是快,但是等于是利用了不用排序的特点。排序的办法,在高维度(也就是k sum问题,k>2) 的时候,nlogn 就不是主要的时间消耗成分,也就更适合 2 sum 的 sort 后双指针扫描查找的办法。

那么,对于 k sum, k > 2 的,如果用sort的话,可以 对 n - 2 的数做嵌套循环,因为已经sort过了,最后剩下的两维用2 sum的第二个办法, 时间是O(nlogn + n(k-2) * n) = O(n(n-1)),空间O(1)。 但是这样跟纯嵌套循环没有什么区别,只是最后一层少了一个因子n。有什么办法能优化?
就是说,对于 k sum (k > 2) 问题 (一个size为 n 的array, 查找 k 个数的一个tuple,满足总和 sum 为0), 有没有时间复杂度在O(n(k-2))的办法?

之前常规的一层一层剥离,n 的次数是递增的。只有在最后一层,还有两个维度的时候,时间开销上减少一个 n 的因子,但是这样时间开销还是太多

我们可以通过对问题分解来解决
举个例子 [..., -5,-4,-3,-2,-1, 0,1, 2, 3, 4, 5, ...] 要找 4 sum = 0. 那么先分解 4 分成 2 sum + 2 sum 来解决,但是这里的子问题 2 sum 没有sum = 0 的要求,是保留任何中间值。只有当子问题的 2 sum 解决以后,回归原问题的时候,我们才又回归原始的 2 sum 问题,这时候 sum = 0
子问题,空间和时间消耗,都是 O(n2). 回归大问题,时间消耗,是O(n2).

假设 k sum 中  k = 2m, 那么一共有 m 层,会有 m 次分解
分解到最底层,时间空间消耗 从 原始 O(n) 变为新的 O(n2).
分解到次底层,时间空间消耗 从 O(n2) 变为新的 O((n2)2)
...
到达最顶层,时间空间消耗就都变成了O(n^(2*m)) = O(n^(2logk))

和之前的方法 O(n^(k-1)) 相比,O(n^(2logk)) 的时间是少了很多,但是空间消耗却很大。
因为子问题无法确定把哪一个中间结果留下,那么就需要把子问题的结果全部返回,到最后,空间消耗就很大了。整体效果算是空间换时间吧。

通过 问题的分解 + hashtable 的运用,能明显减少时间消耗, 但是空间消耗变大是个问题。比如说,如果有106的 int 类型数组,我如果用这个hashtable的办法,就要有1012的pair,这就有 10T 以上的空间消耗。

问题的分解是个很好的思路,但是中间值得保留迫使空间消耗增大,这和用不用hashtable倒没有很大关系,只是说,如果不用hashtable,时间消耗会更大。

另外,还有一些题目的变形,比如如果要求所有组合,满足
sum < k,
sum = k,
sum > k,
或者是 closest to k
遇到这些变形的时候,hashtable 的做法就显得乏力了,但是嵌套循环的方式却仍是可行的。尤其是对closest to k 这种非确定性的要求。


Summary of five practice of Leetcode 18: 4 Sum

Dec. 29, 2017

Introduction


It takes over 6 months to learn one algorithm similar to Leetcode 18: 4 sum, and also each of five practice is helpful and also documented. I just need to go over them again and figure out what to learn from those practices.

4 sum algorithm


5th practice, Dec. 27 2017, here is the blog. After the practice, I updated the code review code with this version to replace 4th version written in Nov. 2017, and also added some commented in the question.

4th practice, Nov. 4, 2017, here is the blog. After the practice, I posted the question on code review.

3rd practice, August 31, 2017, here is the blog.

2nd practice, April, 2017, here is the blog.

May 2017, Leetcode 18: 4 sum practice is here.

Here is the link to search 5 practice using label: 4 sum practice, Leetcode 18: 4 Sum.


Thursday, December 28, 2017

Full stack academy

Dec. 28, 2017

Introduction


I had a mock interview 12:00 PM, and my peer just finished his full stack academy program. And I spent extra hour to talk more about the algorithm and data structure. I was so amazed at his performance.

Here is JavaScript for me to review.
Here is JavaScript for binary search inorder successor.

Full stack academy


Plan to do some study about full stack academy program.

It is 9:38 PM, I am watching 20 minutes video. Here is the link.

It is 3:43 PM, I am working on Leetcode code review. I just start second time to watch the video of full stack academy as well, the link is here. 30 minutes, a panel discussion at our "Back to the Stack conference", where a few alumni came back to our campus to talk about their lives after Fullstack.

Time to learn object-oriented programming

Dec. 28, 2017

Introduction


It is time for me to watch some object-oriented programming course on pluralsight.com. I plan to watch some videos of object-oriented programming, I just need to spend around 12 hours to watch those videos, and then take some notes.


Courses


Here is the list of courses I can watch before January 2, 2018.



Leetcode Number of Island II

Dec. 28, 2017

Plan to study the algorithm Leetcode Number of Island II.

Follow up


1/21/2018 3:19 PM
I like to follow up on this algorithm. I spent over 10 minutes to read the discussion about one solution. I like to put Java code into github and create a gist first, and then I will write a C# solution as well.

Also plan to study the algorithm blog written in Chinese, the blog link is here.

Leetcode 200: Number of Islands

Dec. 28, 2017

Introduction


Plan to study the algorithm Leetcode 200: Number of Islands. I got the advice to work on the algorithm from my mock interview peer on Dec. 27, 2017.


Every algorithm there is a story about hard working programmer

Dec. 28, 2017

Introduction


It is another normal mock interview practice Dec. 27, 2017 10:00 PM. My task is to write another binary search algorithm called root of a number. I have worked on binary search algorithm over 30 times last 9 months, I have wrote so many blogs about the algorithm as well. But this time I still made a mistake in the edge case, while (start < end) should be while( start <= end), and the peer was very smart to tell me that if x = 1 then my code will return -1 instead of 1. The peer was surprised that I found the bug missing = sign in less than 2 minutes before. I did not tell him that I recently had same issue and wrote a blog about the case as well.

Here is my C# code on this practice.


Binary search algorithm


The peer asked me in the mock interview a question, "how come you are so good at binary search algorithm?" I told him that I have worked on binary search algorithm last 6 months over 30 times. I have mock interviewed the peer using binary search algorithm over a few times. I made a few mistakes before, and one time the peer advised me to focus on middle, do not work on start or end edge case.

I still remembered that my last practice on this number I did wrong on the binary search range, but the mock interview platform does not catch the error.


Newton method


The peer shared me his Newton solution to solve the root of number. Here is the code.

Recursive algorithm


I spent extra 30 minutes to use ShareCode to discuss with the peer, I like to use my favorite algorithm Binary Search Tree Inorder Successor to test how good he is in terms of confidence to solve the recursive algorithm.






Leetcode 18: 4 sum

Dec. 27, 2017


Introduction


It is the cold day in the city of Vancouver, I spent the whole day inside the home for another vacation day. I have a whole week off. I only went out with my friends to take a walk in Burnaby central park, and I booked 3 mock interview 12:00 PM, 8:00 PM, 10:00 PM.

First peer is working on next January Google onsite interview, second peer is working on next January Facebook onsite interview. Third peer is from Shanghai, China, he had Google onsite 4 years ago, and then he prepares to get another one.

I was busy to observe how other programmers work on problem solving. My thinking is that young people are smart, and very good at communication, but lack of challenge in daily work or practice compared to working on Hackerrank contest advanced level algorithm. I want to see those determination and dedication in their problem solving process in the future.

 I went through the Hackerrank contest to work on advanced level algorithm, I understood that it is so hard to make things work, score zero from over 5 hours for a depth first search, but the algorithm cannot meet the time complexity requirement.

Those young peers are trying their luck, they will experience how tough the fight is after their onsite interviews. There are some candidates with a lot of practice and being able to solve the problem in less than 10 minutes.

Here is my records of practice:



Leetcode 4 sum


I had mock interview 8 PM. The peer has experience to work for Microsoft, and then I got advice how to improve my code.

My last practice is on Nov. 14, 2017. I wrote the blog the document the practice. And after that I posted a question on code review website but no one gave me review.

Dec. 27 is my fifth time I worked on the algorithm, I wrote exactly same code of 4th practice. But the peer gave me a few of advice to simplify the code.

The above code can be simplified. First look at the redundant code to manipulate the dictionary.


The first is to reduce four variable to two variables, save i, j instead of arr[i],arr[j], i, j. Secondly line 17 and line 23 are the same, extract them outside the if/else branches.

Here is the code after simplification.



Actionable Items


Look into those four companies, Nitanix, Uber, Qualtrix, Splunk.




Wednesday, December 27, 2017

Code review: Binary search tree inorder successor

Dec. 26, 2017


Introduction


I spent over one hour to write a question to post on code review website. As a mock interviewer, I like to get some help from the code review website.

Here is the code review link.


Tuesday, December 26, 2017

Count the connected components in a matrix

Dec. 26, 2017

Introduction


It is the good idea to write a recursive function to complete the algorithm in less than 10 minutes. I could not do it. My last practice took me near 20 minutes or so.

Here is my last practice at 10:00 PM on Dec. 24, 2017.

Today I had a mock interview at 6 PM, and then the peer wrote a C# version as well. I will write one using similar idea, to check recursive for left/ top/ right/ bottom four neighbors if the range is ok and also the value is 1.





H-Tree recursive solution

Dec. 26, 2017

Introduction


I had a mock interview at 6 PM this evening and then I met a programmer who prepared a test case for my algorithm. I felt that the peer is the very good programmer and then I gave a lot of feedback on his coding review as well.

Here is my C# code to write a recursive function to implement H-tree.


Code review: Leetcode 10: regular expression matching

Dec. 26, 2017

Introduction


It is another mock interview 12:00 PM. I had chance to help the peer solve Leetcode 10: regular expression matching. I did not expect that the peer can solve the problem almost perfectly. I was so surprised to learn from the peer how he wrote an elegant recursive function using while loop.

Code to study


Here is the peer's C# code. I like the implementation.

The above code failed last test case, "abaa" and pattern string "a.*a*". It should return true.

Here is the code to fix the above bug. The code passes all test cases on mock interview platform. But it failed on Leetcode 10 online judge.

Index out of range error, Line 28: System.IndexOutOfRangeException: Index was outside the bounds of the array. Last executed input: "ab" and ".*c"

Line 28: If(text[tIndex] != pattern[pIndex])


Actionable Item


After spending over 30 minutes to debug the issues using Leetcode 10 online judge, I learned that the recursive solution has a lot of issues. Later I will revisit the solution and give more objective comment on this solution.



sliding window in the array

Dec. 26, 2017

Introduction


It is the mock interview of 12:00 PM. I have to practice a solution for k-messed array sort. Since C# does not provide minimum heap class, the peer told me that I can apply sorting similar to insertion sort.

After we discussion to use linear scan k + 1 window to find the index with the minimum value, and then swap the start position with minimum index, I wrote the following code.

C# code is here.

My argument is to write the code and also the code can pass all mock interview platform test cases. Although the time complexity is O(kn), k is the size of slide window, n is the array's length. The optimal one using minimum heap is better with time complexity O(nlogk).




It is a good journey

Dec. 25, 2017

Introduction


It is the good journey for me to take first 6 interviews as the interviewer, and I got first 6 rating with full score 5 as an interviewer. In order to do that, I had to be super patient to the beginner of mock interview, and extend the algorithm to challenge the strong player. To overcome technical difficulty on mock interview platform, I used two times to get audio outside mock interview platform, 2.5 hours using wechat with a Chinese, one hour using Microsoft skype with a professional.

Let us take easy, and look at the performance below. Da Da Da, I made it as I chose to be, an advanced interviewer.


Extended algorithm


Here is the leetcode link for the extended algorithm for mock interview on 10:00 PM Dec. 26, 2017.

What I like to do is to write down my talk as an interviewer to help the peer, give the hint and encouragement to solve the problem.

I like to use this talk to encourage myself to be a lazy programmer, and always delegate the task and do as little as possible in terms of writing code.


Before I write the story let us look at the binary search tree, and talk about a few test cases first.


Test case 1: Given value 25, how to find the successor null?
Test case 2: Given value 14, how to find the successor 20?

Assume that I am very lazy, try to solve as little as possible, find a most simple task first for the algorithm. 

Given the node is the same as the root node. What is the successor? 
It should be the root node's right subtree's minimum node. It does not matter if the root node has right child or not. We can just delegate the task to the right child, using one recursive call. 

In other words, we are saying that the left subtree all nodes in the tree are smaller than given value, it is impossible to find root node's successor in left subtree. The root node itself cannot be the candidate. 

Next step, what if we relax the condition, root node's value is not bigger than given node's value? We apply the same logic. 

Now go to next test case. Given value 14, how to find the successor 20? 
Since the root node's value is bigger than given node's value, the root node can be the successor or after the successor in the list of nodes based on inorder traversal. 

Let us delegate the task to its left child, ask the return of successor. If the successor is not existed in the left subtree, then root node is the successor. 


Follow up 

Dec. 26, 2017 9:59 AM
Actually the extend algorithm is a binary search algorithm. To search binary search tree inorder successor given two nodes, root node and given node, what we need to do is to handle base case. 

If the root node is null, then return null. The most challenge part is when to return root node as a successor. Given the above tree, root node is 20, only when given node is 14, the successor is root node 20. How can we tell that it is 20?

Get connected


Give some feedback about mock platform. Maybe there are too many traffic for video and audio, my peer asked me if it is always like this. I told him that I did a few time, get audio no video from wechat or facebook or skype. 


Monday, December 25, 2017

Code review written in C++

Dec. 25, 2017

Plan to review C++ code written by the peer in the mock interview on Dec. 25, 2017 6:00 PM.

Here is the C++ code.

Swap technique applied to search minimum missing number

Dec. 25, 2017

Introduction


It is almost 2 hours mock interview. I had chance to practice the algorithm to use swap technique again. And then the peer asked me to write the optimal solution as well.

I wrote the solution, and did the white board testing. Run the code and there is a dead loop, timeout.

Code review


The C# code is here with constraint "The array cannot be changed".

The C# code is here with the permission to change the input array.

Follow up 


The C# code can be optimized for the case to change the input array. The code is optimized and the link is here.

How to work with graduate student?


It is learning experience for me to work with the peer today. I learn that if I treat the peer with patience and great attitude, then the peer will treat me with patience as well. Just be patient and learn some C++ through mock interview today. 




Listen to your elder sister (III)

Dec. 25, 2017


Introduction


It is good experience to have a elder sister who is a physician and working full time last 30 years. I never need to worry about anything about my mom until Nov. 11, 2017 as a daughter. I know that the doctor sister has an idea how to solve the problem, my mom enjoyed her life and lived 87 years old. My mom enjoyed most of her time in her last 17 years.

I still remembered that my elder sister wrote letters to urge me to help my mom to purchase her own home first time when she almost turned to 70 years old in 1999. Life was so different when you have some one to share her story in different country. I should have more understanding about big difference earning income as a full time employee in two countries 17 years ago when I was younger, work as a full time software engineer in my first year in United State.

Now as a Christian, I understood that the important thing is to be humble and give the help to the need to follow the bible teaching.

Listen to your younger sister (II)

Dec. 25, 2017

Introduction


It is the biggest treasure to have a younger sister, specially after my mom passed away since Nov. 11, 2017. My younger sister is a lecturer all her career to teach biochemistry in the university of Yichun, Jiangxi province. We all are busy and grow apart, and then follow different directions in the life.

I like to write something to say how good it is to have a young sister in your life.

Research and law


2000 - 2001

My young sister started to teach in the university when she was 23 years old. She helped my mom to apply visa to USA back in 2000 when she took one year break to study in the university of Beijing as a teacher exchange program. Therefore my mom had chance to visit Florida twice in 2000 and 2001, first time my mom stayed in Florida with me four months, and then second visit was five month long. I had work visa H1-B at that time and worked for a online entertainment software company.

2016 - 2017

My nephew grew up so quickly, he spent 6 years to live with my young sister and my mom from 2005 to 2011. And my younger teacher sister helped him to learn and study very hard. And then he spent two years with my elder teacher sister, another one in Shenzhen city from 2010 to 2001. At that time, his English teacher tutored him to work on English since my teacher sister did research and analysis on his potential and weakness to prepare his university admission examinations. English is easy to get improved in short training or tutoring.

Now back to July 2016 my teacher sister told me to work on sponsor application, go to check the law. I listened and then started my journey.

It is my turn to be a grown-up and help young generation. It is hard and take it slow, invest time to learn and figure out things by myself. I did complete the sponsor application at the end of 2017.

Listen to your elder sister (I)

Dec. 25, 2017

Introduction


I have an elder sister who retires in China and she always laughs at me. She boasts all the time how social community country treat her really nice as a teacher. She worked all her career as a high school geography teacher and enjoy everything. She has visited more than 20 countries.

It is the biggest help if I can make some dollars in the city of Vancouver by investing a property five years ago. If I have more financial freedom, then I can enjoy myself to practice more algorithm, write more coding blog, less concern to work on something else to make ends meet.

But my point is to respect your elder sister, honor the woman who brought up a son, a mom of a staff engineer in California. If I can be close and dearest sister, I may add over $100, 000 dollars with less pain and sweating. The most important is to listen to your elder sister.

I have four sisters and one brother, one sister is such a smart one and she told me that I should buy a home five years ago. Now she thinks that it is too late to purchase a property in the city of Vancouver.

I was stubborn, and I set up my priority different way.

Bible teaching is to settle down a new place, be part of the community at the very beginning. Instead I choose to live an easy life, do not put myself under pressure of mortgage, and focus on my career.

Learning technology and work on career is hard to achieve with less guidance. Compared to listening to my elder sister,  I should have followed her guidance as she relocated to Guang dong province in 2000. I should choose to live a nice and comfortable home first, and enjoy the urban work and life as a Chinese, purchase a home and work with biggest bank first, and then figure out how to survive later.

I have been a Canadian last eight years now. I have to catch up and learn something about personal finance.


Leetcode 10: regular expression matching

Dec. 25, 2017

Introduction


It is time to write hard working stories that will touch my heart again, I always like to read my own blogs and then get encouraged to work on more on algorithms.

I started my six round of mock interview after I finished around 30 algorithm a few days ago, so I started to use ID: 2017 to start a new round. Also I chose the setting called: Advanced level of interview, one level below the top one. The top one is to eat and sleep on algorithm. I just could not believe that I had to chance to learn so many things about the industry and how good people are to study or work for a software engineering career.

It is Christmas holiday break, and I decided not to hang out with friends. I choose to work and meet new people. I set up a few mock interviews on Dec. 24, 2017 from 4:00 PM, 8:00 PM, 10:00 PM. You know what, since machine learning algorithm picks up my setting of advanced level, this round is different. All first three interview questions for me to interview peer are hard level algorithm, same algorithm same day for three peers, Leetcode 10: regular expression matching.

Hard working graduate student


First peer is a university master graduate student with top 50 ranking university in California, I had chance to learn how to write a dynamic programming solution from him. I spent extra one hour 20 minutes to discussion other algorithm with him as well.

Dynamic programming solution is not easy for me to figure out. I had some questions about the implementation, and then I asked the peer. But I could not be convinced for three cases, a*, for zero time, one time or more than one time.

Here is the blog for the review of the peer's code.

The peer complained to me that he could not find enough interview opportunity for intern. I gave the advice for him, increase online presence. Write on quora.com or coding blog, document the practice. The peer is really good at dynamic programming algorithm.


Linear scan the array

Dec. 25, 2017


Introduction


I had a mock interview at 12:00 PM. I wrote a linear scan algorithm and finished the algorithm in 22 minutes. The peer asked me if I solved the problem before, and then I explained to the peer that I solved similar algorithm, there are two famous algorithms related to linear scan algorithm, test how good you can write a for/ while loop. One is called Leetcode can plant flower, one is called hackerrank Bear and gene.

Code review


The C# code is here.


Sunday, December 24, 2017

Leetcode 10: regular expression matching

Dec. 24, 2017

Introduction


It is the hard level algorithm in Leetcode. Leetcode 10 is also called regular expression matching. I have practiced over ten times, and I always choose to use recursive solution.

I had a mock interview and the peer solved Leetcode 10 using dynamic programming.

Code review 


Plan to study the dynamic programming solution. Here is the Java code.




Leetcode 315: Count of Smaller Numbers After Self

Dec. 24, 2017

Introduction


It is the hard level algorithm, and binary search tree can be selected to store the array of elements from left to right. The only trick is to increment the count whenever the new node is bigger than root node's value.


My practice


I like the hard level algorithm. So what I do is to go over the brainstorm first, and think about sorting the array, save the index; and then figure out the time complexity could not beat the brute force O(n<sup>2<sup>), and then think about store the array into binary search tree, and also keep some calculation in the same time.

I underestimated the problem, and I spent 30 minutes to write code but I could not pass the sample test case.

Here is C# code which could not pass the sample test case.

Follow up 


I asked the peer after mock interview on Dec. 24, 2017, a university of southern California university master graduate student, he analyzed using dynamic programming approach. We reached the agreement after 10 minutes, the solution may end up O(n2) at last.


Follow up 


I asked the peer after mock interview on Dec. 27, 2017 10 PM, a software engineer over 10 years experience in the city of Shanghai,he explained to me the divide and conquer algorithm similar to merge sort. I was not able to follow his explanation.


Array linear scan algorithm

Dec. 24, 2017

Introduction


It is the Christmas day and I like to take some time to practice mock interview. And I had 10:00 am mock interview.

The algorithm is the array linear scan and reverse the array.

Here is the C# algorithm.

Code review


Plan to find all past practice first and review every practice here.


Interval overlap?

Dec. 24, 2017

Introduction


I had a mock interview 10:00 PM to work on the algorithm related to interval. And then I had chance to practice the algorithm in 30 minutes. I explained the algorithm by some drawing first and then write the algorithm.

Dec. 23, 2017 practice is 30 minutes long. Here is C# practice. The code could not pass edge case to return empty case, need to figure out later.

Interval overlap


There are more than one way to define the interval overlap. To choose minimum value of two start values and then maximum value of two end values, and also check the max value is bigger than the minimum value.

Interval algorithm 


It is time for me to review my practice on interval related algorithms last few years.



Saturday, December 23, 2017

Code review: At least 2 paths down the binary tree have the same sum

Dec. 23, 2017

Introduction


It is my most favorite algorithm in the world in June 2016. I had to go through the transition to accept myself as a software programmer, and learn how to improve myself through this simple algorithm. I did the practice and then stopped without writing an optimal solution in June 2016. Now after more than 12 months, I know that at the time I do not have high standards on practice at all.

Here is the algorithm I practice in June 2016.

I reviewed the code on Dec. 23, 2017 and asked the question on code review website. Here is the code review web link.

June 2016


It is tough to deal with frustration, what I did is to write a blog to study the failure on June 5, 2016. I was so excited to go over one day meeting with the most highest standard software company. And then I experienced so many issues through meetings. One thing is that I did not perform very well on the similar algorithm using C# LINQ.

Add one more paragraph


One thing I like to do is to add one more paragraph on the code review. Since I do not get any upvote after 24 hours, so I like to step out and do something to help myself.

Here is the paragraph:

Code improvements
I decided to make a few improvements based on my last practice over 18 months ago. Internal class is used instead of external class. I choose to use camel case for public method, and rename the function DuplicateCheckingPathSum to make the function name self-documenting. Specially I took 10 - 20 minutes to go over those stackoverflow links to learn LINQ and also ASP.NET C# class and I found that those links are really helpful for me to warm up LINQ. It is tough for me to see that after 18 months I still do not make big progress on LINQ and the functional programming syntax still looks like foreigners to me.
Most of important change is that I learn better recursive function design after 18 months. I was surprised that I ended my last practice with so many issues. The base case should be selected to avoid duplicated count of each path. I like to see the depth first search algorithm specially a recursive function is written in very structured way, base case is very clear and also the recurrence formula afterwards.

Follow up 



Dec. 25, 2017
Early in the morning I got code review, and I was so excited to read the review. Here is the link of code review.



Code review: Leetcode 10: regular expression matching

Dec. 23, 2017

Introduction


It is the smart idea to ask the classical algorithm on the code review website. I did one on Dec. 22, 2017. I got one down vote, and 3 upvotes in first 24 hours. Compared to the classical algorithm Leetcode 10, I asked another algorithm question based on my practice, here is the link. I am still waiting for the first upvote for the algorithm.

Here is the link.

Friday, December 22, 2017

Recursive function practice

Dec. 22, 2017

Introduction


It was another 10:00 PM mock interview. I had one algorithm to work on, write a recursive function.

Here is my C# practice.


Blog written in November, 2017, here is the link.

Blog written in June, 2017, here is the link.


Structure of depth first search


After I practice depth first search with so many peers, until this November, 2017, I start to learn that it is very important to write the algorithm in a very structured way.

First, I should check edge case to prevent the run-time exception,and then I like to write a base case. What is most simple task I can complete to do the work. For the above algorithm, it is the node without any children. Every one can write one line of code to figure out the minimum path. There is only one choice, and one value, just return the value.

So next step is to ask all your children nodes to do the same task for you, and then you only have to find the minimum one, and add current node's value to it.

To peer with so many talent programmers in the world, I have chance to learn the recursive algorithm in most fashion ways. Because if I do perform very well, the peer will give me extra time to share some tips, and also I have time to learn a new person, and get connected with another hard working person.

Analysis of the algorithm


I like to write some review about my practice in November. The peer found the bug in my code. Usually it also tells me that I should work on the analysis of the algorithm. Do not let the problem come to the bug, I should catch it in the analysis of the algorithm.


Statistics


Past practice on the algorithm last 5 rounds:
.1107 12/21, .sh 9/14, .mp 7/30, .ca 6/14, .fl 5/7

Thursday, December 21, 2017

Buy or rent?

Dec. 21, 2017

Introduction


It is the most hard question for me to answer at the end of 2017. I start to look for a place to purchase, I have not purchased any property last 18 years.

I like to do some research 10 to 20 minutes a time, and write down what I should learn.

Let me make my research less serious. It is coding blog, we like to document how hard we work. But a laugh always cheers me up.

My friend laughed at me recently, 5 years ago the property is $300,000, now it is $500,000 in the city of Vancouver. Now it is the peak time, but I start to plan to work on the purchase.


Research topic


How to define the most important thing in the life? Recently I talked to my friend in Florida and he told me that he has to pay $1000 medical insurance by himself, and then I compare to Canada MSP medical insurance. The insurance in Canada is much less compared to Florida. So I decide to purchase a home in Canada.

How to decide which city to purchase? Surrey or Langley or Abbotsford?






Book reading: Mathematics for computer science

Dec. 21, 2017


Introduction


It is time to enjoy the book reading: mathematics for computer science.

Leetcode 10: regular expression matching

Dec. 21, 2017


Introduction


I met a peer who likes to share his regular expression matching dynamic programming solution last Sunday, so I know that he is very talented programmer. I like to review his analysis and his code written in C++.

The analysis is here. C++ code implementing dynamic programming is here.