Tuesday, February 6, 2018

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.


Monday, January 29, 2018

Say goodbye to the weekend

January 29, 2018

Introduction


It is time to say goodbye to a busy weekend, now it is morning time 7:40 AM before I prepare to leave home for a new work weekday. Last weekend I had thirteen mock interviews first time. The interview started from the Friday evening and ended in the last hour of Sunday evening.

Let us take a look the schedule, I only went out for quickly grocery shopping in Saturday, I did not have time to go out to play sports, swimming.

It is so enjoyable to spend time to talk about algorithm using C# language, JavaScript, Python, Java this weekend, I met so many talent programmers and it is the first time I practice so many algorithms in less than 3 days.

Good experience


I applied some skills I learned from church small group meeting to the mock interview. I am getting better on those algorithms, learn a few things to make me better to write dynamic programming, recursive function.


What I have learned


Do not memorize the algorithm. Try to show some reasoning.

I still remembered that the peer told me that he read my post on quora.com about mock interview when I shared my coding blog, and then I had chance to get the trust from the peer, he shared me a lot of tips and also got invited to join Google foobar.


Sunday, January 28, 2018

Deletion distance algorithm

January 28, 2018

Introduction


It is very hard for me to learn a dynamic programming solution to solve deletion distance. One thing I have learned is to understand the difference between recursive and dynamic programming. The peer is a latest computer engineering PH.D. from top university, he asked me tough questions. I had hard time to go over the analysis and answer his questions, but I managed to learn and answer correctly.

It is not good to memorize the solution, that is the reason I seek for the advice for each mock interview. This time I had chance to learn from top graduate and understand how important it is to be able to explain the algorithm.

I have to understand the algorithm and be able to defend my analysis. Mathematics is my undergraduate study major, I love to prove something based on theorem.

Analysis and code review 


Here is the transcript I wrote in less than 30 minutes. 

Leetcode 54: Spiral Matrix

January 28, 2018

Introduction


It is the algorithm I have to write on my 10:00 PM mock interview. I worked on the spiral matrix, and it took me in total 20 minutes to explain the solution and write the solution to pass all test cases.

Code review


The peer told me that I can save the space using four pointers instead of visited array. I explained to him that the mock interview is for me to write the correct solution using minimum time.

Here is the C# code I wrote.

Advice from the peer

January 28, 2018

Introduction


It is something I learn from the work. I have to let people talk and then learn something from the conversation. Recently the office coworker shared the tip to use Vancouver library card to access Lynda.com 6000 courses.

Today I had 8:00 PM mock interview. The peer shared with me the tips what to learn through so many resources. I write down and will look into later. One thing he told me is to use New York library card to access Lynda.com courses.

Here is the link.


Udemy

January 28, 2018

Introduction

I had a mock interview 6:00 pm, the peer advised me to check udemy.com. You can get a good quality course on react over there.


Learning JavaScript

January 28, 2018

Introduction


I had 6:00 PM mock interview. I had 30  minutes to learn how to write JavaScript from the peer, who went through full stack academy.

JavaScript code


Here is the code I reviewed to apply binary search in the array and find smallest index which equals to the element value on the index.


Four Sum problem

January 28, 2018


Introduction


It is busy weekend. Today I had a mock interview at 4:00 pm,  I felt that I were a student to be interviewed for an algorithm, the teacher is questioning me everything, and make sure that I understand everything I write.

Code review 


Here is the code.

Highlights of interview:

1. First the data type of function on line 44, getTwoSum, its return type dictionary's key is integer, not string;
2. Second, the array should be sorted in ascending order. I forgot to write the first round.
3. Discussion of dictionary search algorithm time efficiency.



Power function do it yourself

January 28, 2018

Introduction


It is the algorithm the peer shared with me on 10:00 PM mock interview January 27, 2018. Learning algorithm is kind of fun. I have to read python code, and also I learn how the peer wrote down his solution using memoization, and later he told me that the friend told him to remove memoization, just use one recursive call to reduce the number to half.


Code review


Plan to study the algorithm and review it later. The code is here.




Find first missing number

January 28, 2018


Introduction


It is the algorithm for me to work on this 12:00 PM mock interview. I like to review the analysis and code.


Code review 


Here is the code with the analysis.


Leetcode 6: Zigzag conversion

January 28, 2018


Introduction


The peer asked me to work on Leetcode 6: Zigzag conversion today after the mock interview. I wrote down my idea, here is the link.


Guess 4 digit number algorithm

January 28, 2018

Introduction


It is very good practice to ask the peer to give me an algorithm to work on, through the discussion, I can learn something from the peer quickly.

This is the algorithm I like to continue to work on. It is called "Guess 4 digit number algorithm".



I got Google foobar invitation

January 28, 2018

Introduction


I read the story on code review website about Google foobar. And I got the invitation to join Google foodbar. I was so excited to have chance to work on some algorithms over there.


Convert a binary search tree into a double linked list

January 28, 2018

Introduction


It is good idea to ask the peer what is his/ her favorite algorithm. I had a mock interview 12:00 PM today, after mock interview, we discussed several algorithms. One algorithm is to convert a binary search tree to a doubly linked list.

Here is the link on Leetcode discussion.

Learning python

January 28, 2018

Introduction


I met a peer second time in one month and she used python. What I like to do is to learn python through mock interview, and write down notes when she coded. Python is easy to follow and quickly to write. The peer told me that she works day time using C++ but she chose to write python for mock interview.

The peer started to write python since she was in the university, actually she graduated from MIT. The python code should be pretty good.

Python code about matched brackets


Here is the code.

Saturday, January 27, 2018

Design a data structure

January 27, 2018

Introduction


I had a conversation with the peer after mock interview. One thing we discussed is about the data structure design. He asked me to design and data structure to do insert for a range numbers from array, I quickly thought about binary index tree. And he also said something about interval algorithm.

Algorithm related to binary index tree


It is time for me to look up Leetcode and find the algorithm. I asked the kindergarten adventures on code review stackexchange.com a while ago. It is time for me to learn the algorithm through a simple example.


H-Tree algorithm

January 27, 2018

Introduction


I practiced one more time on H-tree algorithm at 4:00 PM mock interview. I was really appreciated to have chance to look into time I need to spend. I tried to cut time short, so I meet the expectation from the interviewer on interviewing.io. Time is money, time is asset. If I can make it 10 minutes, why I like to spend 20 minutes. Extra 10 minutes I can work on another algorithm, usually it only takes 10 times to work on one algorithm, the interviewer does not need to see you code every algorithm.

Today I spent 20 minutes to write the algorithm with some analysis. But I tried to cut the analysis to minimum.

Algorithm code review


Here is the code.


Use bit manipulation to solve problem of power of n

January 27, 2018

Introduction


I really like Roger Federal as a professional tennis player, but I never have any chance to talk to him. But do not worry, today I had a chance to talk to a programmer from Switzerland, he speaks exactly same as Roger Federal does, a Switzerland accent. And he also tried to teach me the algorithm called power of n using bit manipulation.

I did some research after mock interview. Here is one article about the detail.

I just could not believe that I got best help from top programmer through mock interview this weekend.

Here is the algorithm the peer wrote. The great thing is to watch him how he did the testing using 52 and then after the testing, he cleaned up the white board testing code. He just quickly demoed how he wrote a new code and also tested and put it in the production, nicely presented after removing those test cases.



Catalan number

January 27, 2018


Introduction


It is another mock interview and I had to work on the algorithm related to Catalan number. This time the peer dropped a hint, do not need to use previous row, only use current row and then save the space. I wrote the code based on his advice.

Algorithm 


Here is the code based on the advice from the peer.


floats number and operators and how to get maximum number

January 27, 2018

Introduction


I had this mock interview on interviewing.io, and the I noticed that the peer is anonymous but he is machine learning algorithm computer science Ph.D. with a few years experience.


Mock interview performance


Here is the transcript related to the discussion and my code written in the hurry. The code is copied from the record video at 55:01/ 1:00:16.

Highlights of mock interview performance:
Line 44: I tried to define the subproblem, what are the subproblems?
Line 120 - 128: I narrowed the subproblems to max/ min value. 

After mock interview 


Here is the algorithm I tried to write after mock interview, it has some bugs in there.

For example, [1, 12, -3], if we use the recursive function, then it is 1 - (12 * (-3)) = 1 + 36 = 37, but since the precedence is flat, 1 - 12 * (-3) = -11 * (-3) = 33. So we may have to process the array in reverse order instead, I have to investigate on the issue.

Here is the code from the friend I met on pramp.com.

Major hint complaint


I got feedback from the peer, the peer told me that I need major hint and also the solution is a brute force solution.

Here is the feedback I got after January 25 mock interview. 


Follow up 



The solution is attached here. Also I posted the question on codereview.com, and the link is here.


Hard level algorithm is a good choice?

January 27, 2018

Introduction


It is most important to learn something from Silicon Valley engineering culture. I am in the city of Vancouver last eight years. Last week I had 3 mock interview on interviewing.io, I learned something about mock interview the first time.

Hard level algorithm is biased


The interviewer told me that the very hard level is biased for people who have worked on the algorithm before. The interview from facebook mostly is focusing on the data structure efficient, bug-free code. Dynamic programming or string manipulation algorithm can be very hard to work on.

I had to work on group of anagrams, and then I felt so good and then spent over 25 minutes. But the interviewer gave me feedback. In order to pass his interview, the interviewee usually takes 12 minutes to go over the problem and also write the solution.

I have to work on his advice. The peer has over 500 mock interview experience so he told me the truth the facts in terms of competing for any position in top ranking start up and software companies these days in Silicon Valley, California.

Here is my mock interview practice.

Follow up 


Feb. 12, 2018

I meet a peer on mock interview platform, and then he told me that he got rating 4 out of 4 on this algorithm group of anagrams. He did talk about all four possible solutions, including short word using sorting with time complexity O(n * mlogm), m is word's length;



Friday, January 26, 2018

Leetcode 10: regular expression matching

January 26, 2018

Introduction


It is another 8:00 PM mock interview. The peer is top ranking computer science master student, and she helped me to work on the dynamic programming solution of Leetcode 10: regular expression matching. First time after I practiced over 5 times on mock interview, I wrote a dynamic programming solution and passed all test cases.

Code review


Here is the C# code.

Highlights of changes in mock interview discussion advised by the peer. I told the peer that she paid so expensive tuition as an international student, and spent half hour to help me and tutor me to work on dynamic programming solution, I am so appreciated her help. She also thanked me to give her advice as well.

1. Line 15, change dp data type from int to bool;
2. Line 32, add i - 2 >= 0 in case index-out-of-range error;
3. line 39, use row, col variable instead textIndex, patternIndex;
4. line 50, remove dp[row, col] = 0 since the peer told me the default value is 0;
5. line 58, need to change dp data type from integer to bool, otherwise the expression is too hard to read.


Follow up 

May 9, 2019

Here is the code I wrote and fixed the issue and passed online judge.

Thursday, January 25, 2018

Web Security on frontendmaster.com

January 25, 2018

Introduction


It is time for me to calm down and work on some courses on frontendmasters.com. My favorite topic is web security. The course link is here.

Now it is 9:12 PM, I have a mock interview at 9:55 PM. So I have over 30 minutes to watch the video.


Wednesday, January 24, 2018

Light speed to learn binary search algorithm

January 24, 2018

Introduction


It is another 10:00 pm mock interview. I met a peer and then I observed how quickly the peer came out from the Newton method, and in less than five minutes, he came out his own style of binary search algorithm and solved the problem.

The peer told me that he learns the programming by himself.


Code review 


Here is JavaScript code.

The peer wrote a few lines of console statement, and then he just quickly removed them once the code passed all test cases. Just unbelievable the peer can learn the binary search in light speed.

The code is not perfect, but the peer showed me how good he can learn and how fast he can learn to write the algorithm and also solve the problem.

Since it only takes a few minutes for the peer to learn, I called it light speed.


Follow up 


Feb. 21, 2019
The interviewee joined Google in July 2019.

Mathematics series

January 24, 2018

Introduction


It is interesting to look into mathematics series, so I can prepare better for the algorithm problem solving. I still remember that first time I came cross this encryption and decryption problem, it took me over one hour to get used to work on the combinatorics analysis and find the sum of source string in encryption formula.

I had a mock interview 10:00 PM today. And I practiced one more time to do analysis of the algorithm and also wrote a solution. The peer is a new graduate from top university of USA. So I had good time to communicate and write down the combinatorics formula. Feel so good. I still remember the feeling to work on Introduction to Combinatorics home work back in 1996 when I worked on Math department graduate study in Florida Atlantic University.

Code review


Here is the C# code. I like to improve my analysis of the algorithm. In terms of writing and how to derive the formula through the problem statement.

Specially I added extra two lines (line 61 and line 63) so that I can explain the idea to the peer and he could understand better.


Actionable Item


Plan to read Series wiki article. The link is here.


Leetcode 54: Spiral Matrix

January 24, 2018

Introduction


It is the algorithm I have practiced over 6 times in mock interview and also interviewed other 6 peers from March 2017 to January 2018. On January 23, 3018 10:00 pm, I had my first mock interview on interviewing.io platform, and then I had to work on the algorithm. What I learned through the mock interview is to get rid of those 4 for loop inside a while loop. In other words, the interviewer told me that in order to perform a 20 minutes coding interview, I have to write only one loop, and adjust the direction accordingly.


Mock interview 


Here are the hints the interviewer gave to me:

1. After 20 minutes, he wrote down four directions in two one dimension array.
dr = new int[]{0, 1, 0, -1}
dc = new int[]{1, 0, -1, 0}

2. After another 10 minutes, he gave second hint to use visited array [][] to mark the visited node.
3. After that, he gave me another hint, how to write a checking for direction change.

if(row < 0 || row >= rows || col < 0 || col >= cols || visited[row][col] == 1)
{
      // change direction
}

Here is the transcript I copied from video clip at 50:00 of 51:00.

After the mock interview 



This the first time I used interviewing.io to practice mock interview. It turns out that the interviewer is much strong in technical skills and also interview skills. I have played the interview recording twice, and here are something I have to work on.

1. Do not interrupt the interviewer.
2. Say something like "Let me think about two minutes.". Actually calm down and think carefully in two minutes.
3. Stay calm and speak slowly.
4. Take hint and write down the hint quickly, and really think about hint. Follow the hint.
5. It is too slow to take the hint, and work out a solution based on the hint.
6. I should work on the example and write fully functional C# code in mock interview.
7. Check the time I spend and act fast.

Define the keywords for the problem, write down in mock interview. So it is very easy to discuss with the peer for various ideas. Seek and you will find, brainstorm the ideas related to time complexity, space complexity.

Direction - There are four direction. Change direction if need, in the order of clockwise, starting from top left corner (0,0).
Range - Stay inside the array
Visit - visit each element in the array only once. Do not visit more than once.
Order - follow the order of clockwise, start from (0,0).

Ideas can be searched through those keywords. Let us go over one keyword together.

For example, direction can be managed smartly using array for four direction, or manually specified. Every edge in one direction can be specified by start point and end point two variables, but it also can be implicitly specified using visited array. Just relax and talk to the peer in mock interview, and go over each possible options. Evaluate pros and cons, have a conversation.

Follow up 


Here is the C# code I wrote after the mock interview. I really like the idea and the solution is so easy to write, I write on purpose to add fourDirections in order to make the code more readable.

I am planning to post a code review on the stackexchange.com as well. The link is here.


Feeback is gold



It takes a village to raise a child. 
Interviewing.io is my new village.