Saturday, February 10, 2018

Say hi to New York again

Feb. 20, 2018

Introduction


It is true that I met a peer from New York this morning 12:00 PM mock interview. I already met over 10 people from New York. I started to learn one thing a time from people working in New York industry.

It is fun and also people are more active to reach out to other people as well.

New York style


I did hear a few things about New York. How things work in the city of New York. Today I also learned a few things through discussion of JavaScript coding of a H-tree algorithm.

Here is JavaScript code.

Since the peer told me that he has over 10 - 12 years ruby on rail experience, so I asked him the question how he designed the JavaScript function, basically it is like functional programming style. const drawHTree = (x, y, length, depth) => {. 

I asked the peer to extract variable top_y, bottom_y, left_x, right_x four variable, and then I asked the peer to write to DrawLine the length of line and declare a variable for totalLines. 

I asked the peer to  count how many H-tree by steps, and then he quickly came out the time complexity. 





How to make a successful mock interview as an interviewer?

Feb. 10, 2018

Introduction


It is the sixth mock interview on the second anonymous platform, so I had chance to meet programmers from top ten companies in west coastal area and also graduate students from top universities, and then I had chance to get some feedback about the algorithms I choose, and the behavior issues I have to correct.

First of all, I should give the interviewee the agenda, including how many algorithms I should give. This is the advice I got from Feb. 9, 2018 mock interview. I do not want to scare the interviewee when I ask the interviewee to stop the first algorithm, and I like to move on to the next algorithm.

My goal is to test how confident the interviewee is, how good the interviewee is on algorithm and data structure problem solving. I will continue to ask and then see if I can find any major issues through the interviewee. Since the interviewees are with experience both sides, and also with very good education, so usually I just pay more attention to learn something through the experience.

People varies in terms of soft skills, and learning new things outside the work. Sometimes people can not hide if they do not practice algorithm and data structure long time, like catching up in a month of two.

Algorithm


The interviewee asked me where to find the resource about the algorithm I asked in mock interview. I know that the interviewee is very confident and also independent thinking. So in order to prepare an algorithm to be my mock interview algorithm, I also try to build a profile for the algorithm. I share the algorithm float number and operations on the stackexchange.com website. Here is the link.

I continuously study one algorithm called spiral matrix, Leetcode 54. First time I learn that it takes so much time for me to catch up so many ideas and then I know how smart people are to get the good idea to survive in a mock interview and write a perfect working solution in ten minutes.

Yesterday the interviewee took over ten minutes to read the problem Leetcode 54 and came out the idea, and then he tried to use extra space to avoid so many edge cases. I really like the idea, it is something I am looking for in mocking interview.

I honestly told the interviewee yesterday that some one did much better than him, passed through all four algorithms I gave to him in first 35 minutes, and he did 30 minutes system design interview as well. If you work for a big company, basically you are competing with your coworkers. The anonymous interview is supposed to be hard, difficult to pass the interview. Do not get frustrated if you get low rating. I just make sure that you are guided to the optimal solution, so you learn something and do not waste time on mock interview.

The precondition is that I also have to learn the mock interview algorithm from all the interviewees, I have to build depth and breadth of knowledge of the algorithm.

What I have learned as an interviewer


I did find one thing through the mock interview. I have to learn how to take turn to express my idea and also try to catch the right time.


Educative.io

Feb. 10, 2018

Introduction


It is another 10:00 AM mock interview. I had good time to write a recursive function called minimum path sum from root to leaf node, and also I had chance to watch the peer to perform a recursive function using depth first search.

Advice


One advice I got is to watch courses on educative.io. The peer took two courses, one is algorithm, one is system design.


Friday, February 9, 2018

Leetcode 54: Spiral matrix - based on directions

Feb. 9, 2018

Introduction


I keep learning the spiral matrix algorithm through Leetcode discussion, and then I came cross the discussion of Leetcode solution based on the directions.

Here is the discussion note I like to share. I read carefully about the analysis and then write down and make some modification, so I can follow closely the thinking process of the author.

Analysis based on directions


I like to go over the discussion here as well. Here is the C# code. Also I like to add this solution to the question I asked on stackexchange.com so that I can get some feedback later on.

Thursday, February 8, 2018

Leetcode 54: Spiral Matrix

Feb. 8, 2018

Introduction


One more solution is here based on using two variable to switch direction clockwise. I read the idea from Leetcode 54 discussion, and then tried to write one using C# language.

One of ideas is to go over as many Leetcode discussion as possible, and then I will vote the idea I like and actively share my feedback. Because I like to use this algorithm for my mock interview as an interviewer, I like to do as many research as possible.

Please write at least ten ideas using C#. Be well prepared and learn one algorithm very well. I can  use the algorithm to tell who is real talented programmer in the world.

Using two direction variables

Here is C# code.


Leetcode 54: Spiral matrix - think recursively

Feb. 8, 2018

Introduction


It is my idea how to train myself in the practice. It is to involve the discussion of Leetcode. Every algorithm I should give out 10 votes for 10 different ideas, and also write C# code based on the idea.

I did some research based on my practice of Leetcode 301 recently, and I found out that my practice has some issue. And I wrote a blog how to learn a hard level algorithm on Leetcode.com.


Recursive solution


I studied the solution today, and I like to write a C# code based on the idea. It is the great warm up of recursive function, and also nice to review base cases in the design of recursive function. Here is the C# code.



Wednesday, February 7, 2018

Easy, medium and hard level algorithm as a combo

Feb. 7, 2018

Introduction


It is so interesting to meet a peer fourth time in less than three months starting Nov. 2017, and I had to work on Sudoku solver algorithm the third time. The first time I did write the algorithm, second time I skipped, and the third time I skipped, but the peer gave me favor to ask me a few more algorithms. He asked me if I like to have a medium or hard level. I explained that I should handle hard level algorithm since I am not a new graduate, so he started from easy, and then medium and the hard level three algorithms in the row. The whole discussion took less than 40 minutes.

House robbery easy level, extend algorithm medium level, and word square hard level three algorithm.

Here is the transcript. I will look into those algorithms.

The pseudo code is written by the peer. I got the idea and explained to the peer. But the peer likes me to write down the pseudo code, so he did for me instead. Because I was too nervous, I could not believe that I figured out all three algorithms correctly, but I could not write clearly as I did in explanation using pure English words. Certainly the peer was very good at whiteboard interview, he could write very clearly than I should have done as an interviewee.

House robbery


Leetcode 198 easy level, Leetcode 213 medium level


Word Square


Here is Leetcode discussion link.



How to learn a hard level algorithm on Leetcode?

Feb. 7, 2018

Introduction


I chose to work on Leetcode 301: remove invalid parentheses, and then I spent 30 minutes to work on the algorithm last Saturday Feb. 3, 2018. And this past Tuesday night I browsed all the blogs and then I found that I worked on the algorithm last July 2017. So I was so surprised and then I had to look into what is going on. How come I do not have any clue that I work on the algorithm over hours.

I was so surprised to read my own blog and then just amazed that how time can take away everything. Hard work and long journey of coding, design and study. Here is the blog dated on July 2017. I even wrote an answer in discussion and then got 3 reputation. I did not aware that I had positive reputation, last time I checked I only have zero reputation.

How to learn a hard level algorithm? 


It is important to practice again and again on the same hard level algorithm. My last practice in July 2016 seems not working very well, because I could not remember too much detail about how to write recursive function, tips and tricks.

This time I changed the plan. I like to focus on more on ideas. I tried to write more than five blogs for each idea of the algorithm, and write down my own notes for each idea. Hopefully I can learn more things from one hard level algorithm.

There are so many algorithms, I can not work on a lot of them. Just get familiar with hard level one.

What I like to do is to leave 10 discussions comment for other people's post in leetcode discussion panel, and also vote up to 10 ideas to encourage people sharing. Get involved more about sharing ideas on the hard level algorithm. Do not be biased on ideas.



Leetcode 301: Breadth first search and pruning (VIII)

Feb. 7, 2018

Introduction


It is interesting to read the gist I prepared for the discussion of breadth first search and how to prune the algorithm. Here is the link. And here is the C# code.


Leetcode 301 - How to speed up the algorithm? (VII)

Feb. 7, 2018

Introduction

I spent time to read the discussion how to speed up search. Here is the gist.


Leetcode 301: Remove invalid parentheses (VI)

Feb. 7, 2018

Introduction

It is interesting to read and study the solution based on breadth first search. Here is the gist I prepared for my study.

It is time for me to warmup the skills using Queue to solve an algorithm. Here is the C# code.


Leetcode 301: remove invalid parentheses (V)

Feb. 7, 2018

It is such a good workout that I wrote a C# code based on one of solutions in Leetcode discussion. Here is my C# solution.


Leetcode 301: remove invalid parentheses (IV)

Feb. 7, 2018

This is one of solutions I like to study. First I prepare the study note for myself. Here is the link.

Leetcode 301: remove invalid parentheses (III)

Feb. 7, 2018

I like to review the study note later for this algorithm. It is written in Chinese. Here is my gist file.


Float number and operators algorithm

Dec. 7, 2018

Introduction


It is the fifth mock interview on the platform, and I am the interviewer. I have to be very careful since my last mock interview I got very low rating, the peer said that he wasted time, and I learn something quickly.

I am still trying to use the same two algorithms, but I like to make sure that I have to lead the peer to the optimal solution, this way if I am real interviewer, interviewee will like to work with me. Also I have to show up as the professional, act like a real interviewer.

Julia interviewer 


As an algorithm daily mock interviewer, I am lazy to think about the solution using dynamic programming. Today the peer wrote one dynamic programming solution for the algorithm. I learned quickly, it is so easy, nothing different from deletion distance algorithm I HAVE practiced over 20 times.

I know that sometimes I have this false impression and think that I am super talented.

Here is the python code using dynamic programming, I reviewed the code. The code passes test case [1, 12, -3] with maximum value 33.


The power of the algorithm


I try to practice nice as an interviewer, and then it turns out that the interviewee is super talented. He passed Google onsite interview recently. I just could not believe that I have learned how to behave in mock interview, I just need to follow the interviewee and watch the video how he answered each question.


Bayesian statistics


Do you like to read the performance report using Bayesian statistics. Definitely it is learning experience for me, I really enjoy the ride so far. I met top performers, over 10 years programmer working on search engine, a person can write a compiler (I guess), and a young master graduate who can pass through google onsite.

It is not hard for me to learn one algorithm very well. I just try out for difference interviewees and then learn from the experience.

spiral matrix algorithm

Feb. 7, 2018

It is my decision to start to work on Leetcode 54 Spiral matrix again. I like to go over all possible solutions through Leetcode discussions, and then vote some of them, and write C# version.

One thing I can do is to work on the same algorithm but use various approach. And I need to understand what the difference is, what makes impact on time consumption on writing, easy to avoid edge cases handling, and what is the production code.

After I practiced over 10 times on the algorithm starting from March 2017 to January 2018, I found the weakness of my practice.

Tuesday, February 6, 2018

Binary tree at least 2 path sum same

Feb. 6, 2018


Introduction


I spent 20 minutes to review the post on code review, and then I wrote the solution based on the review. Here is the code review link, I asked the question over one month ago.

Code practice


Here is the C# code integrated with all the reviews. I use the algorithm to warm up recursive function and think about using it in anonymous interview in short future.




Float numbers and operators

Feb. 6, 2018

Introduction


It is the algorithm I like to use in anonymous interview. I used it four times, and I started to think about more on the algorithm.

Brute force solution


Here is the brute force solution. This algorithm is really challenging and the peer complained to me on Feb. 5, 2018 that I should lead the interviewee to the optimal solution, otherwise it is waste of the time. The algorithm is for interview of principle lead or programmer, not even for senior.

There are a few issues to handle besides using recursive function, flat preference, max and min used to reduce the numbers from four to two, and also using memoization or dynamic programming will lead to optimal solution.

I will continue to use the algorithm and see if there is a super talent interviewee, and I can learn from the experience how to write the optimal solution.


Being interviewer: Deletion distance and long common subsequences

Feb. 6, 2018

Introduction


It is 8:00 PM mock interview. I had chance to learn a way to solve deletion distance using long common subsequences.

The idea is to find the longest common subsequences in two strings, for example, "heat" and "hit", the common subsequence is "ht", so the distance is "heat" and "hit" length sum minus 2 times length of common subsequence "ht". It is 7 - 2 * 2 = 3.

Code review


Here is Java code.


Leetcode 214: Shortest palindrome (I)

Feb. 6, 2018


Introduction


It is hard level algorithm and I like to learn the algorithm. It is called Shortest palindrome.

30 minutes thinking


Since the algorithm is hard level, I plan to practice at least 10 times. Today I spent 30 minutes to thin k about the solution, and address possible issues in the brute force solution.

Follow up

Feb.15, 2018

I did spend over 30 minutes to read the discussion, and then wrote C# solution based on Java code. I did not fully understand KMP algorithm yet.


Deletion distance dynamic programming

Feb. 6, 2018

Introduction


I still have difficult time once a while in terms of solving dynamic programming solution. The underneath recursive design of dynamic programming takes more time to practice.  I had a mock interview last weekend and the peer showed me his way to solve the deletion distance.

It is such nice learning experience from the peer. The code is written in Java and the link is here.

Most of important is that the peer showed me how he proved that recurrence formula is correct. Here is the transcript of the analysis.


Follow up 


I asked the peer in mock interview and then we discussed the formula why distance("heat","hit") = distance("hea", "hit").

Here is the discussion:

 //$dog and $frop,
  //$hit, i =   3 $heat, j = 4
  //f[$hit][$heat] = f[$hi][$hea]
  (f[$hit][$hea] + 1)
  (f[$hi][$heat] + 1)
  (f[$hi][$hea]  <- minimum
    min(f[$h][$hea], $f[$hi][$he]) + 1
  )


Let me write down the explanation given by the peer on March 12, 2018. First let me read his explanation and then figure out his reasoning.

First the peer thinks that it is better to add extra char to stand for empty string "", using '$' char.

There are 3 choices to determine the deletion distance between two string "$hit" and "$heat". There are three choices, in other words, here is the expression:

f[$hit][$heat] = Math.Min(f[$hi][$hea], f[$hit][$hea] + 1, f[$hi][$heat] + 1),

We should be able tell that minimum one is f[$hi][$hea].

Follow up 


July 9, 2018

The peer contacted me to ask practice together. I was so surprised since he won ICPC regional contest in 2012. It is the first time I have a peer to practice together with highly competitive skills in contest.

I just quickly looked up his review back in Feb. 3, 2018 6:00 PM. What I did is to check date connected on linkedin, and then found the mock interview round login, and then looked up algorithm. And then I found the blog, and mock interview feedback.


Ready for a new week

Feb. 6, 2018


Introduction


It is so exciting to change my goal for my algorithm and data structure practice. I start to learn from the mock interviews, and try to find things to help me to be a better person as well.

I had 12 mock interview from last Friday to last Sunday.

Practice highlights


I tried to teach a dynamic programming solution in mock interview and got some good feedback from the peer. Learning is so much fun and I also had chance to learn how a young graduate learns to handle a difficult dynamic programming solution.

I struggled on word count practice and actually I wrote i++ instead of i-- on line 33, and it took me more than 5 minutes but I could not spot the error. The peer is a computer science PH.D. student and he told me that if the index-out-of-range, you not need to check the pointer null. So reasoning is something I have to work on to narrow down the possibilities.

Through the practice I learn that it may be a good idea to build a habit to write a loop in ascending order and then change the inside statement of for loop instead. After mock interview, I tried to compare with my last successful practice and then identify the issue. Programmer time is no longer valuable if I have to spend time to find those trivial error since I need more strong analysis skills and also willing to apply to the bug fix.

I also observed an experienced programmer and learned how he troubleshooted his code and fixed bugs in less than 5 minutes on this binary search algorithm.

I also wrote a sorting algorithm and then noticed that the API should not be called swap two index's value, instead it should be called moveFromOneToAnother. The practice is here.

I also had chance to learn from the peer who has more than three years pythons experience. She showed me how good she can solve the binary search algorithm in this practice.


The valuable lesson to be a good interviewer

Feb. 6, 2018

Introduction



I never expect that I have to learn how to be a good interviewer until I finished 10:00 PM mock interview today. I got the feedback from an experienced programmer.


Code review


I have to review the code the peer wrote and also need to think about the feedback I got.

First algorithm is about Spiral Matrix. I did review the code and the code is very good.

Second algorithm is about float number and operators, I had to review the brute force solution. I did learn something from the code as well.

My feedback


It is hard to learn to be a good interviewer. I have to learn to focus on the basics and remove my bias.

The interviewee wrote very readable code and also very easy to work with. He did show his solution on the first algorithm Spiral matrix, the code he wrote demoed his very good analysis skills and high coding standard in his daily practice. The second algorithm is float numbers and operators, and then the peer wrote a solution but failed to pass test case [1, 12, -3], and then the peer asked for the hint, and then he came out the idea by himself to write a brute force solution using O(N^4) time complexity and also space O(N^4). The interviewee also taught me something as an interviewer, what I should learn. For example, I have to leave impression to the person, first the difficult level of the algorithm, is the algorithm for senior developer or junior developer. There are several areas the interviewee can improve, like coding style, communication skills, like algorithm analysis of the second algorithm. How to come out the optimal solution, reduce the time complexity from 4^N to 2^N? Based on the conversation after the mock interview, I think that interviewee taught me a good lesson to be an interviewer. I decide to let him go to next round.


Feedback from the interviewee


I have to make mistakes in order to learn to be a good interviewer.

Here is the feedback. Please close your eyes.

Would you want to work with this person? No
How good were the questions? Waste of time
How helpful was your interviewer in guiding you to the solutions? Not helpful at all
Help your interviewer get better!
Please put more thought into the questions you're asking others. Usually there are multiple ways to solve any problem - you as interviewer should be fine with any of the ways interviewee solves posed problem.


Play with the code


It is unbelievable that the interviewee wrote production ready code, so I changed the code to C# programming and ran the test case, it works for [1, 12, -3] with maximum value 33, the C# code is here.

I am not sure how the interviewee came out the design and wrote almost perfect code for a brute force solution. I continuously played the code and added some comment to look into those variables. Here is the C# code with some comments.


Monday, February 5, 2018

Algorithm study

Feb. 5, 2018

Introduction


It is so much fun to learn from a person by reading his website. I decided to read the book Element of programming interview, and then I found myself really enjoy to read the website of the author Tsung-Hsien Lee.

Algorithm teaching

Feb. 5, 2018

Introduction


I made the choice based on the peer's recommendation in my last weekend mock interviews. I decide to read the book called Elements of programming interview in Java. And then I started to read preface of the book on Amazon.com. I started to read about two authors. The first one is top ranking university computer science professor, I really like the website, specially with the notes the professor shared when he studied in the college. Those handwriting notes just brought me back to the college age, and the hardworking classmates of Shanghai Jiaotong university and their notes.

I do have very good notes as well. I took a math graduate course back from 2010 to 2014, I like to go back to Florida one day and see if I can find my Introduction to cryptography course home work, I like to share them on my blog as well.

Plan to read the website http://users.ece.utexas.edu/~adnan/


A great professor must be a good student when he is in the college. 

Sunday, February 4, 2018

Find smallest substring containing all keys

Feb. 4, 2018

Introduction


It is the algorithm I have to write for my 10:30 PM mock interview. The peer was very helpful and I had 30 minutes to complete the analysis and code, I did fix the grammar error in last minute and pass all test cases.

I can tell the difference. Since I understand the process of sliding window containing substring, how the left pointer can slide through if the substring contains all keys. I had one practice in January and then I got a few advice to optimize the algorithm. This time I could write the algorithm much quickly.

The peer advised me to speed up coding if I can.

Code review


The C# code is here. The peer advised to add extra variable to store the start position of substring, I added variable on line 21 called startIndex.




10 minutes to be interviewed

Feb. 4, 2018

Introduction


It is the game I play after the mock interview. Today after the mock interview, I gave two questions and asked peer to solve. One is spiral matrix and another one is maximum number of chunks. The peer is very experienced programmer, went to onsite facebook last year, second round Google phone screen, and since last 12 months he finished 300 algorithm on leetcode.com. I just saw the big difference compared to me, since he worked so hard on 300 algorithm recently, it is so easy for him to follow the hint to work on spiral matrix to write a simple while loop solution, it only took him less than 10 minutes to come out a total different solution.

After 20 minutes, I asked him to give me one algorithm to be interviewed.

10 minutes to be interviewed


Here is the transcript for my performance. I just could not believe with 4.9 out of 5.0 reputation, I continuously in the row this afternoon partnered with three programmers, with good intern experience or education background, with 4.0 GPA master graduate student. I think that it is so easy to learn thing quickly through the discussion.

I definitely learned something today.


Elements of programming interviews in Java: The insider's guide

Feb. 4, 2018

Introduction


It is hard decision to choose what to work on. It is a busy year, I just started to subscribe frontendmasters.com, but I find that it is hard for me to sit down watch a few hour of videos. It takes time to learn new things, I need to practice after I watch something.

Today the peer of my mock interview shared with me a book, he read the book and bought a paper copy; so he can read the book all the time.

The book is called "Elements of programming interviews in Java: The insiders' guide". This is the second time in less than one month two peers recommend me to read the book. One got Google onsite interview, one had facebook onsite interview less than one year.

Elements of programming interviews in Java


This will be my book. I like to find my most favorite three algorithms in next 30 days.


Saturday, February 3, 2018

Binary search algorithm

Feb. 3, 2018

Introduction


It is so interesting to know that mock interview is shorter than ever before. I met a peer who had intern experience with top software companies, and then he only spent less than 10 minutes to write the code and pass all test cases.

Both of us finished mock interview algorithms in less than 30 minutes.

Binary search algorithm


Here is Java code related to binary search.




Binary search tree algorithm

Feb. 3, 2018


Introduction


It is another mock interview at 4:00 pm, I spent around 15 minutes to analyze the algorithm and write the code. I worked on the binary search tree algorithm called Find inorder successor, and the peer shared with me his advice, it is also easy to check first left parent instead of comparing the value with parent node's value.


Code review


C# code is here.


New algorithms please!

Feb. 3, 2018

Introduction

It is time for me to set up a goal to work on more algorithms from Leetcode.com. There are over 600 algorithm on leetcode.com, new questions almost come out every day.

It is time for me to learn from the peer to prepare for onsite interview, I met a few people to prepare for onsite interviews. I met a peer one week ago, and he shared with me his Google document last month practice. From Dec. 1 to January 18, he practiced more than 30 algorithms on Leetcode.com. He is preparing Google onsite interview.

I finally spent 30 minutes to go over those algorithms, and then select some problems and decide to go over those algorithm. One of my favorite algorithm is called Leetcode 351: Unlocked Android App.

Mock interview


Mock interview is easy to continue right now for me. I have worked on those algorithm over ten times.

In order to push myself outside comfortable zone, I have to start to work on new algorithms. There are over 600 Leetcode algorithms, I have only worked on more than 100 algorithms.



Array of array products

Feb. 3, 2018

Introduction


It is the time to write the algorithm in less than 10 minutes. The algorithm is called Array of array products. Once the dynamic programming idea is used, all I have to remember is to do one multiplication from left to right iteration, but from right to left iteration, two multiplications are needed, one is to multiply the left product with right product, and then apply dynamic programming to right product using one multiplication.


Code review


Here is C# code.


Recursive function design talk

Feb. 3, 2018

Introduction


It is the third time I met the peer on mock interview platform. The peer worked on the algorithm root to leaf path sum minimum value, and then the peer explained to me his design in five minutes.

Tail recursion, local state, global state


The peer explained to me his idea of solving the problem. Local state is prefixSum variable, global state is minSum variable.

Here is the C# code.


60 minutes to reach out the community

Feb. 3, 2018

Introduction


It is the best time in the morning for me to reach out the community, I had 10:00 AM mock interview and I met a young graduate student in United States, and then I had to work with her to find a solution using binary search. Based on my past practice, it is very easy for me to give out some practical advise. I also enjoyed the learning process of Java programming language.

Code review


The idea used in the code is to find the pivot index in the array, the element's value is smaller than previous one, or it is the first one in the array.

After the pivot index is found, the normal binary search can be applied.

The Java code is here, I reviewed the code to remove index-out-range bug in binary search algorithm.

Java Array.binarySearch API end index is exclusive, so the peer fixed the bug to add one in the input arguments.

After the mock interview, the peer told me that she really likes the mock interview experience. She learned a few things from me. Also I shared the website called frontendmasters.com to her.

It is amazing that the new master graduate student is aiming to web development, and learn react framework and try to use mean stack to do development.

Largest smaller binary search tree key

February 3, 2018

Introduction


It is 10:00 AM mock interview and I had to work on the algorithm called largest smaller binary search tree key.

Analysis of the algorithm


To search the key in the binary search tree, we do not have to traversal the whole tree, all we have to do is to start from root node and then go right or left, until meeting the dead end. For example, the node does not have left node but we have to check smaller value, or the node does not have right node but we have to check larger value. 

I made so many mistakes in past practices, and I remembered the time I was so nervous and then think about largest smaller, how to keep the largest one in the set of numbers. Since the value of smaller one is found, those numbers are in ascending order, only one variable is needed to keep current one. 


Code review 


Here is the C# code.


Leetcode 301: Remove invalid parentheses (I)

Feb. 3, 2017

Introduction


I like to work on a hard level algorithm on leetcode.com. Also I do not like to rush and find the answer as I do sometimes. Through the learning experience of Leetcode 10: regular expression matching, I know that it may take me 10 practice before I can fully understand the hard level algorithm.


First 30 minutes


On Feb. 6, 2018 I had chance to work on the algorithm called Leetcode 301: removed invalid parentheses. I like to write down the notes and see if I can find the answer through the first 30 minutes work.





Leetcode 679: 24 Game

Leetcode 503: Next Greater Element II

Leetcode 490: The maze

Leetcode 351: Android Unlock Patterns

Feb. 3, 2018

Plan to work on the algorithm. Read the blog here first.


Friday, February 2, 2018

Leetcode 425: Word Squares

Leetcode 272: Closest Binary Search Tree Value II

Leetcode 42: Trapping Rain Water

Feb. 2, 2018

Plan to work on hard level algorithm Leetcode 42.

May 23, 2018

I could not believe that I could not come out the idea to calculate the rain water when I was asked by the interviewer on May 22, 2018 8:30 PM. I asked one of Chinese graduate student to help me, give me some mock interviews and this was the first algorithm he asked me.

I talked about descending stack, and the interviewer asked me why it is the descending stack. And also the interviewer asked me to give out the correct brute force solution. I noticed that my brute force solution is also not correct. I need to find left boundary for the current bar which should be maximum height of prefix elements.

Here is my C# solution written after the mock interview.

There are three issues to fix in order to pass online judge. First one is to check base condition, check array length is 0 on line 26; second one is to apply Array.Reverse API, it has been called three times. And the last one is to add if condition statement on line 49.

Leetcode 685: Redundant Connection II

Feb. 2, 2018

Plan to work on hard level algorithm.

Float number and operators algorithm

Feb. 2, 2018

Introduction


I asked the peer to solve the float number and operator algorithm on Feb. 1, 2018 10:00 PM mock interview. It is such a learning experience for me to learn how the peer came out the recursive solution.

Code review


The code has some issue. Subproblem should include maximum and minimum value.

The Java code is here.

Actionable Item


I will write the code based on the idea of recursive function.

Leetcode 54: Spiral matrix

Feb. 2 2018

Introduction


It is the second time I asked leetcode 54: spiral matrix in the anonymous interview as an interviewer. I met a peer who was willing to be interviewed, and followed my hint and try to write a solution using one loop instead of four for loops for each direction.

Code review


Here is Java code to review. The peer spent around 20 minutes to work on coding, I was able to see how good the peer can write readable code.

I told the peer that he did better than me. When I was asked this algorithm and the idea to write one loop only, it took me more time to come out the ideas, and I needed two hints, one for direction array, one for visited array.

Compared to the peer, I knew that I have to learn to stay open and think hard in the mock interview.




Minimum path from root node to leaf node in a tree

Feb. 2, 2018

Introduction


It is 8:00 PM mock interview. My algorithm is to calculate the minimum path sum from root node to leaf node.

Code review


Here is C# code.

Thursday, February 1, 2018

Leetcode 10: regular expression matching

February 1, 2018

Introduction


I understand that there is no hard algorithm, only lazy student. I have spent over 10 times to practice Leetcode 10: regular expression matching last eight months. Usually the peer writes a perfect solution and it takes 30 minutes, I experience a lot of good learning experience from those peers.

Last two months I start to write dynamic programming solution as well to solve the problem.

One hour practice


On January 31, 2018 I had a mock interview, and then I spent one hour to be interviewer. The peer  wrote a perfect dynamic programming solution. And the peer shared his argument that one time for b* pattern is not necessary in implementation.

Argument to think about

b* can repeat zero time, more than one time. But one time can be covered by zero time and more than one time this two cases.

Here is the transcript I reviewed.


Leetcode 394: Decode string

Feb. 1, 2018

Plan to work on the algorithm.


Leetcode 726: Number of atoms (V)

February 1, 2018

Introduction


It is hard level algorithm and I like to learn one thing a time through the practice. This practice is based on the coding blog written in Chinese, and I like to develop a blog based on the idea.

Here is the Chinese blog link.

Analysis of the algorithm


The idea is to find the first close bracket ')' and then look ahead for the number and look backward to find open bracket to match the close bracket.

Here is C++ code to study. I will write a C# solution based on C++ code.

Leetcode 726: Number of Atoms (IV)

Feb. 1, 2018

Introduction


It is very interesting to read one of discussion and the code is implemented in python. What I like to do is to spend 30 minutes to go over the analysis, and then get the idea how python code works.

What I like to do is to go over the analysis again, and write down the analysis in my own words. Spend more time on the analysis, and then understand the algorithm one thing a time.

Python code


Here is the discussion link.


Study of the blogger


Here is the link I like to study about system design.

Analysis of the algorithm


Regular expression
The first is to understand how to read regular expression, the atom can be expressed in the following expression: ([A-Z]{1}[a-z]?|\\(|\\)|\\d+). I just learned how to write regular expression in 5 minutes.  I documented my practice on algorithm on word count engine algorithm on January 25, 2018 and learn how to write regular expression for delimiters.

The number of atoms
The regular expression can be used to split the input string, and the only four tokens are discussed.  (1) An atom (2) A number (3) Open bracket (4) Closing bracket.

Let us go over a few test case and then how to read them in char array.
An input of Mg(OH)2 will be tokenized into: ['Mg', '(', 'O', 'H', ')', '2'].
An input of 
K4(ON(SO3)2)2 will be tokenized into: ['K', '4', '(', 'O', 'N', '(', 'S', 'O', '3', ')', '2', ')', '2'].

How to solve the problem?
As we iterate through the tokens, there are three cases that we need to handle:
  1. Open bracket - We push a new dictionary onto a stack to keep track of the atoms and its count in this current group.
  2. Close bracket - The next token might be a number/count. Check whether if it is a count. If it is, multiply all the atoms at the top of the stack by the count and combine it with a dictionary below it in the stack.
  3. Normal atom - The next token might be a number/count. Check whether if it is a count. If it is, add that atom and its count to the top of the stack.
Cases 2 and 3 are very similar, so we can combine them.

At the end, sort the atoms alphabetically and format them nicely to be returned.

Leetcode 726: Number of Atoms (III)

Feb. 12, 2018

Introduction


It takes at least 10 times to learn a hard algorithm on Leetcode 726. One thing I did is to study one of C# solution on discussion panel, and review the C# code and try to make it better.

Iterative solution


Here is the C# code I spent over 30 minutes to rewrite. I will continue to review the C# code. The practice is very helpful for me to understand the algorithm.




Wednesday, January 31, 2018

Scalability Harvard Web Developemnent

January 31, 2018

Plan to watch the video again. Here is the link, the length is 1 hour 45 minutes.

Leetcode 726: Number of Atoms (II)

January 31, 2018

Introduction


It is so nice to watch a video of Leetcode 726: Number of Atoms. I like to spend 20 minutes to watch the video first, and then write down some notes here.


Video lesson


Here is the video to watch.


Coding blog


Here is the coding blog. I plan to study the code as well. And then I will write a C# solution based on the idea.

Here is Java solution. I will work on C# solution based on Java code.


C# code practice


I spent 90 minutes to write the C# code. Here is the code. I felt that it is like flatten dictionary, only difference is to handle close bracket to return dictionary. Every close bracket will be handled right away, which likes a leaf node in the tree.

Leetcode 726: Number of Atoms

January 31, 2018

Introduction


It is the last day of January 2018, I like to celebrate the first month of 2018 using one hard level algorithm. I found one today by reading a Chinese algorithm blog, the link is here. The algorithm is hard level one on leetcode called Number of Atoms. I know that it will take some time for me to understand the algorithm with hard level.


Algorithm study


Plan to study the Chinese blog and write down some notes. One thing I like to do is to read the chinese blog, and go over each word, try to put together and make it more readable first. And then write down a few things to look into, highlight them, and plan to go over it again later.

三种方法,第一种采用递归,而后两种采用栈式结构。

 方法一:递归

首先编写一个解析器Parse,这个解析器应当能统计出从当前字符串位置开始,直到遇到一个右括号“)”或读到字符串末尾,然后连带上右括号“)”后面可能跟上的数字,这可做为一段整体。
用一个counter来记录这一段各个元素的个数。最后返回counter。

1.
首先初始化counter
2.
在解析器循环中:
1.
当遇到左括号“(”时,就递归调用Parse;并把Parse子程序中元素统计结果加入当前的counter当中。
2.
如果不遇到左括号,那么会发现一定是大写字母,也就是一个原子名称的开头,那么就统计这个元素的个数。
3.
循环结束后,检查右括号后面是否跟有数字,如果有的话要对当前的counter进行相应倍乘。
4.
最后返回counter。
5. Parse
可以写成一个递归函数,然后用主函数做驱动函数。

方法二:采用栈式结构


和第一种方法类似,不采用递归函数,采用栈来进行操作。(其实函数的递归和栈本就具有极大的相似性)
先初始化counter栈,然后仍旧需要一层循环,直到读完所有字符。
循环中:
1.
当遇到左括号“(” 时一层新的counter入栈。
2.
遇到右括号“)”时栈顶counter弹出,并检查后面是否跟有数字,如果有的话对当前counter进行相应倍乘,并把结果累计到新露出的栈顶。
3.
遇到大写字母,就统计这个元素的个数,计入counter,类似方法一。

方法三:同方法二,但是不手动解析字符串,而是采用正则表达式



规则表达式Regular Expression,通常被用来检索、替换那些符合某个模式的文本.
把字符串分成一个一个独立的块,这里采用的表达式为:"([A-Z][a-z])(\d)|(()|())(\d)"。这里面的块分别表示:可能带有数字的元素如“Fe3”、“H”等;左括号“(”;可能带有数字的右括号“)”、“)3”等。
然后在循环中对正则表达式中的每块进行各自对应的处理。

复杂度分析



无论哪种方法,理论的复杂度相同。但是这里推荐使用第三种方法,因为栈式结构比递归的写法更加简洁, 还有第二个原因, 正则表达式极大地简化匹配操作。

时间复杂度


O(N^2)
这里N为字符串的长度,遍历一遍字符串需要O(N)的时间,但是当遇到左括号时,会对子式的元素向外累加,这就有可能达到O(N)的时间,而总字符串长度为O(N),所以左括号的个数为O(N)(注意大O记号的含义是“不超过”,这里的意思是不超过线性界,而不是等于线性界)。故所花时间为O(N^2),
这里给出一种时间比较逼近N^2的表达式:A(B(C(D(E(F3)4)5)6)7)。

注意:正则表达式的时间界不容易判断,这里正则表达式没有回溯,所以总的时间复杂度不会超过O(N^2),这与正则表达式的实现方法有关。

空间复杂度


O(N),这里无论是栈还是Map,空间复杂度不会超过O(N)。







Being an interviewer: System design - design instagram

January 31, 2018

Introduction


I do not have chance to sit in the classroom to learn the system design, and then I do not plan to learn system design today. But today the peer had super performance, first 40 minutes he passed through all four algorithms, including array, recursive, graph and then dynamic programming. So I asked him to have a system design question, design instagram with scalability.


System design best one


It is so enjoyable to learn through the best system design in the world.

Here is the transcript. And the best thing is that I can watch the video again and again, learn every step he developed the design. The interviewer has more than 10 years experience to work on search engine in the city of Seattle, USA.

Every time I feel stressed to learn system design, I just go back to watch the recording, and then learn from the best.

I remembered one time I met the senior developer working for Microsoft fifth time in mock interview. I told him that I work as an interviewer in another platform. And he asked me how much I get paid. I laughed about it.

Transcript starts here:
end here.

Follow up 

Nov. 15, 2019
I like to review the notes again. I like to spend 10 minutes and learn from my own experience. What should I do in terms of system design? I did not have chance to write so many content in my Facebook onsite in August 2019. I was interrupted before I like to talk about diagram, distributed file system or storage.

maximum number of chunks

January 31, 2018

Introduction


I cannot believe that I have strongest peer in the world and then I just need to find some good algorithms, and then I can get tutored through the mock interview. I could not believe that I got matched with super talent programmer, good lord, machine learning algorithm does great job for me tonight.


Algorithm code review


Here is the transcript to understand the algorithm.

Float number and operators algorithm

January 31, 2018

Introduction


I was thinking whole day how to come out the recursion in the correct order on this algorithm called Float number and operators algorithm. Tonight I met a super talented programmer with over 10 years experience to work on a large scale system, and he taught me how he approached the problem in less than 10 minutes.


Code review


Since I already checked the peer's code skills, I just asked the peer write down a few lines of code and try to get his idea.

Here is the pseudo code. Perfect order to fit for flat precedence. Only one hint using [1, 12, -3] on line 30.


Leetcode 54: Spiral matrix

January 30, 2018

Introduction


It is such a big surprise that my first mock interview as an interviewer turns out big success. The peer solved all four algorithms I asked in first 40 minutes. He is the best peer I have met in my peers, over 150 peers.

Best thing is that I got education how to design a perfect system design: Instagram scalability in 30 minutes. I could not believe that I may interview a top company senior developer in the future.


Code review


Here is the C# code I like to learn. The idea is very clear and it is the production ready code.


Tuesday, January 30, 2018

Leetcode 123: Buy and sell stocks

January 30, 2018


Introduction


I have to learn the algorithm again, I believe that the algorithm of dynamic programming is such an interesting learning experience. It is like seek and hide game, every time I come back to work on the algorithm, it is like a new algorithm. What is happening?

Recursive


Please solve the problem once and then build the recurrence formula. This time I also like to watch the video and see if there are some new tips.


Follow up


Feb. 16, 2018

Here is the gist I saved from the blog to talk about dynamic programming related Leetcode algorithm.

Other two gists are written in Chinese about dynamic programming. Here are the link 1 and link 2.






AlgoExpert - 55 algorithms

January 30, 2018


Introduction


I got advice to look into those algorithms on the website algoexpert.io. I like to spend some time to learn those algorithms marked as free videos first.




So nice a Monday

January 30, 2018

Introduction


It is such a nice Monday, I am back to daily work and try to learn something from frontendmasters.com. Also I had a 10:00 PM mock interview, I learned an idea to work on reverse the sentence, with a minor bug in the implementation.


Code review


Java code is here.