Saturday, April 21, 2018

Being an interviewee: Leetcode 10: regular expression matching

April 21, 2018

Introduction


It is hard level algorithm called Leetcode 10: regular expression matching. I had a mock interview 8:00 PM and the peer told me that I should hurry and complete everything in 30 minutes. I did finish coding and ran my own test case. But my code failed last test case "abaa" with pattern string "a.*a*".

Mock interview


I had difficult time to play with dynamic programming table. I have to match the index of text and pattern string to the dynamic program table, and then I need to build the recurrence formula.

Being a programmer, I learn to be patient again since I could not memorize the thing. I have to make mistake first and run a few simple test cases and fix the bug.

Here is my C# code.

The first twenty minutes was so exciting and nerve breaking. I just write down what I like to do. For example, I wrote something like // base case "" match "a*" or "a*b*", and then I can write code by looking up the comment.

I confused myself about -1, so I wrote down on line 20 as a comment, // pattern[col - 1].  Because I cannot declare an explanation variable because it may be out-of-range of the array. On line 21, I wrote down dp[0, col - 3] which should be dp[0, col - 2] because I confused dp table index with pattern string index.

It is kind of training I like under stress, work on whiteboard, and also work on communication with the peer, manage the peer to make sure the whole process is up to standard.

I wrote a comment like the following:
// base case "a" does not match "" - do not need to do anything - default false

Good thing I did in the mock interview is to run a few simple test case first. When I ran the test case "b" match "b*", I ran into index-out-of-range error, so I fixed the bug on line 21.

My code passes all four test cases I wrote, but failed mock interview platform test case: "abaa", "a.*a*".

Bug fix 


Here is the code I fixed the bug. All my practice on Leetcode 10: regular expression matching can be looked up here.

Please compare my last practice March 29, 2018, here is the blog.

How to deal with tough interviewer?


I had a peer who has more than five year work experience at Microsoft. He is very strict on time limit 30 minutes, so I was in the rush to complete the code and run test cases. At the end of 30 minutes, the interviewer told me that he was very happy for my performance, and he thought that I should be able to fix the bug quickly.



Over 250 mock interviews

April 21, 2018

Introduction


Once a while I like to do a small research, write something for an interesting topic. I have completed more than 250 mock interviews. I have reinvented myself by getting connected to the world.


Stay connected


I was so busy in weekends and evening, I booked the mock interview on a few platforms, and in-between I had some one-to-one session mock interview to help a peer to prepare for important interview.

I used to stay alone and do not talk to people about coding every day. Somehow I have some bad habits formed and then I got complained about.

I used to call my mom every day from 2000 to 2010. I do not have a person to call every day. My sisters are super busy and they do not like to take my calls. One time my sister told me that I called her more than 3 times when I tried to plan to travel to China. Now I call her zero time and I just go ahead to plan things better and efficient.

I like to check wechat or wenxuecity.com website daily. I attend church and get connected to friends regularly. But I like to get more connected to the world, specially those hard working people who likes to advance their software programmer career, where to find those people?

Mock interview


I started to work on mock interview last March 31, 2017 again. It was not easy to build a new habit, specially I have to meet a stranger and also I have to work on algorithm problem solving. It was challenging and it takes some time to get used to practice mock interview. I did not practice from any mock interview from January to March 2017, even though I was advised to practice on mock interview platform.

Once I get used to practice mock interview, and I know that it is an excellent tool for me to learn algorithm, I set up mock interview 5 or 6 times a day in the weekend starting January. 2017.

It is not easy to write down every mock interview practice. I was too busy and I did give over 10 mock interview as an interviewer to ask same algorithm "Spiral matrix print" from January to March 2018. I did not write down one blog for each mock interview, good thing is that I can replay the video on the mock interview platform.


Being an interviewer: Decrypt the message

April 21, 2018

Introduction


It is 12:00 PM mock interview. The peer worked on the algorithm called Decrypt the message. I noticed something is different. The way the peer presented the algorithm is so clear and then I know that I met a very talent programmer.

Mock interview


I also joined the analysis of the algorithm with the peer. We talked about the difference between those numbers on line 8 and line 9.

Here is the analysis and python code. The peer managed to pass all test cases.


Being an interviwee: Root of a number

April 21, 2018

Introduction


It is 12:00 PM mock interview. I have experience to work on the algorithm root of a number over 10 ten times, 5 for interviewer, 5 for interviewee. The peer has strong talent with 1st place twitter big data hackathon. The peer worked on decrypt the message algorithm first, I rated him top 5 - 10% in all over 200 peers I worked last 12 months.

Mock interview


I like to write a binary search and also apply some technique I saw recently using integer to count the numbers.

The peer challenged me about the termination base case, 0.001 is the error range, how I assert that two values are equal using 0.001?

Here is my C# code.




Being an interviewee: Find the duplicate

April 21, 2018

Introduction


It is my algorithm called Find the duplicate in two cases, both sorted arrays has the size close to each other, or one is much larger than the other one. I had the mock interview, after the peer solved the Sudoku solver, I solved my algorithm next.

What I did is great, I gave the analysis of the algorithm for those two cases, I wrote down the analysis from line 95 to line 110. But I came cross a bug of out of memory for my solution to use two pointers. Usually it is show time for me to solve the problem in one try, less than one minute.

Based on my past experience, I was complained one time by a Ph.D. student of University of Florida who prepared for Google phone screen, he told me that I should focus on the error message, and then think about the possible places for the bug. Do not do wild guess trouble shooting.

Related to out of memory bug, it is not index-out-of-range, what is possible reason?

Actually it is a dead loop, but I turned to my first thought. I wrote brute force solution to replace duplicate.ToArray() on line 40 instead at the first try. I did not use my analysis in this trouble shooting.

After more than 250 mock interviews, I found another issue today for my practice.

After a few minutes, the peer told me that I missed two lines of code if the duplicate item is found. I need to advance two pointers.

Code review 


Here is my C# code and the code passes all test cases.


Being an interviewer: Sudoku solver

April 21, 2018

Introduction


It is my 10:00 AM mock interview. The peer worked on Sudoku solver, and then he chose swift language. What he did is to check given numbers on the board are following the rules - row/ column, small grid 3 x 3 matrix not duplicate.

The code he wrote for preprocessing is kind of buggy, so we started to talk and communicate on this piece of code. And then I told him that most of people do not do this preprocessing.

The interviewee wrote code but could not pass the test case, and then I walked through the code, and pointed out on line 18, variable name i is used the second time.

Code review 


Here is the swift code I reviewed for the peer as well. The code passed all test cases.

I gave the advice to write readable code, use meaningful variable names, and also I advised the peer to communicate more with the interviewer. I told him that I met a young master graduate, who was preparing Google onsite, and then he got offer. When I mocked interview him, he kept asking me "am I in right check", "do you think that my coding looks ok", he has determined goal, to write code to pass all test cases he prepared, he likes to develop a complete solution in less than 30 minutes.

I had a small chat with the peer who is preparing Uber phone screen. The peer got the Amazon offer but chose another offer a few years ago. Interesting story, a small world, stay anonymous, smart and hard working young programmer.



Friday, April 20, 2018

Fall in love with marathon

April 20, 2018

Introduction


It is the first time I start to look into how to run marathon, since I have hay fever recently and it brings my concern how to overcome the difficulty. I had chance to talk to one of my friends in 30 years reunion, and he shared his experience to run marathon.

April 27, 2018

BMO Vancouver Marathon


I like to do some research on 8KM Race, here is the link. Here is the link called training room traing clinics.


Thursday, April 19, 2018

Leetcode 126: Word ladder II

April 19, 2018

Introduction


It is the hard level algorithm and I like to spend time to go over a few more ideas through Google search and Leetcode discussion panel. What I like to do is to go over more detail how to address time and memory limit exceeded problem.

I spent over 30 minutes already to go over my past practice and a few ideas, I like to go over this blog.

Algorithm practice


I like to go over the notes written in Chinese in the blog, and then rewrite some of them, make it my own.

As a programmer, most of important for me right now is to be a good thinker. I like to search the blogs and find the idea to help me think clearly. Here is the notes:

LeetCode中为数不多的考图的难题。尽管题目看上去像字符串匹配题,但从“shortest transformation sequence from start to end”还是能透露出一点图论中最短路径题的味道。如何转化?

1. 将每个单词看成图的一个节点。
2. 当单词s1 改变一个字符可以变成存在于字典的单词 s2 时,则s1与s2之间有连接。
3. 给定s1和s2,问题I转化成了求在图中从s1->s2的最短路径长度。而问题II转化为了求所有s1->s2的最短路径。


How do I go over the notes above? 

1. Google search the shortest path in the graph. 
2. How to define a graph? Every word is a node in the graph. 
3. Node s1 and node s2 have a connection -> how to define it?

Let me work on the notes in the following:

无论是求最短路径长度还是求所有最短路径,都是用BFS。在BFS中有三个关键步骤需要实现:

1. 如何找到与当前节点相邻的所有节点。
这里可以有两个策略:
(1) 遍历整个字典,将其中每个单词与当前单词比较,判断是否只差一个字符。复杂度为:n*w,n为字典中的单词数量,w为单词长度。
(2) 遍历当前单词的每个字符x,将其改变成a~z中除x外的任意一个,形成一个新的单词,在字典中判断是否存在。复杂度为:26*w,w为单词长度。
这里可以和面试官讨论两种策略的取舍。对于通常的英语单词来说,长度大多小于100,而字典中的单词数则往往是成千上万,所以策略2相对较优。

2. 如何标记一个节点已经被访问过,以避免重复访问。
可以将访问过的单词从字典中删除。

3. 一旦BFS找到目标单词,如何backtracking找回路径?



Wednesday, April 18, 2018

Celebration of 30 years graduation

April 18, 2018

Introduction


It is the reunion to celebrate the birth of Shanghai Jiaotong university 122 years, and also we met in Shanghai to celebrate 30 years since we graduated together back in 1988 with mathematics degree, we stayed together from 1984 to 1988, and took all courses together. For my case, I stayed with other six girls in the same dorm, and we discussed so many math problems together, and we went out together for so many activities. 

One picture


One thing I like to do is related to my experience to the current China highly developed as a country and also open to new entrepreneurship. What I like to do is to relate my class 70141 to one of top celebrity in Forbes 2018, therefore it is very easy to make connection to the whole world, how education helps people to grow, nurture future leaders and motivate each other to work hard.

I sat in the front row, and rest of my class was in the classroom, including the third row Shen Neil, a billionaire and a Yale graduate. Great thanks to the math professor Xiang Longwan, our instructor of mathematics course took the picture and shared with us after 30 years, on April 14, 2018. My favorite reading of professor Xiang is here, who wrote the recommendation letter for my Florida Atlantic University mathematics Ph.D. program back in 1996.


My favorite reading from Shen Neil is here.


One week China vacation

April 19, 2018

Introduction


It is so interesting to write down my one week vacation experience from April 12 to April 18. I learned so many things from my classmates, Shanghai Jiaotong University alumni. We got together from April 13 to April 15, 2018.


Leetcode 359: Logger rate limiter

April 18, 2018

Introduction


I just came back to the city of Vancouver, Canada this April 18 around 1:00 PM. I had so exciting one week vacation, using Air Canada, GaoTie train with speed over 250KM/ h, and met so many friends in the class of SJTU 70141. We shared stories and fond memory, one of professors showed up a picture of whole class, I sat in the front row, I could not believe that every one of us found in the picture, laughing and such great experience.

One campaign I like to do is to work on ten algorithms to celebrate the China vacation. Also I like to see ideas to recover hay fever I still have and hopefully I can recover sooner and go to work healthy. I have to work on seriously to recover.

First algorithm


It is the algorithm I choose to work on after one week vacation from China. First, I like to study one of blogs related to the algorithm. Here is the blog's link.

I like to go over the blog about Google onsite interview, and find some interesting algorithms to work on.




Tuesday, April 10, 2018

Being an interviewee: Find the duplicate number

April 10, 2018

Introduction


It is my favorite time to play mock interview with a peer third time. I know that it is very hard for me to improve a lot in less than one month. The algorithm I was asked is to find the duplicate number.

Mock interview


Here is my mock interview transcript. I will add some notes later.




Being an interviewer: Find the duplicate number

April 4, 2018

Introduction


The algorithm is my favorite one. I learned a few days ago by a peer, he tested my algorithm problem solving. Here is the quora's link related to the algorithm.

In order to learn better on the algorithm, I gave it to the peer who is preparing Google onsite. I like to figure out how he will solve the problem.

Problem solving


Here is the script for the mock interview. I will write down a few lines of notes for the mock interview later.


Being an interviewer: Leetcode 84: Largest rectangle in histogram

April 10, 2018

Introduction


It is my favorite algorithm and it is hard level algorithm in Leetcode.com. I chose this algorithm to interview a friend met on mock interview. He is preparing next week Google onsite, and I gave him another hour mock interview.

I practiced the algorithm recently, but I found out that I still missed something important. The optimal time complexity is O(n), and it has to use stack to save the index of rectangle left boundary when ascending. The stack is always keeps non-descending heights. Here is the link for my past practices.

Learning is fun


The peer is very organized and also very good at explaining the algorithm. I specially like the way he structured the content.

Here is the script for the mock interview.


Sunday, April 8, 2018

Missing Florida summer 2009

April 8, 2018

Introduction


I spent 14 years to live in Florida from 1996 to 2010. I miss the fun to live in the city of Boca Raton and like to document some fun memory. I also like to clean up all photos and videos I took for those years. I like to get some idea how to make good memory for my life events.


Florida Atlantic University campus





Saturday, April 7, 2018

2010 Buntzen lake hiking trip

April 7, 2018

Introduction


It is such a fascinating world. I had such great time in Florida from 1996 to 2010, I always stayed near Florida Atlantic University campus, so I worked on my computer science PH.D. study from 2001 to 2010, so I hanged out with Ph.D. students and scholars all the time. I landed to Canada in April 18, 2010. At that time, I did not have a job waiting for me, I just landed as a permanent resident.

In May 24, 2018, after one month I landed in Vancouver, looking for a software programmer job in the city of Vancouver. I was invited to go out hiking with my Shanghai Jiaotong university's classmate Zhuang and her family.

First time challenge


I used to stay in Florida all the time. So it is so surprising that I had difficult time to do hiking trip with a group of 20 people. So amazing, I experienced the joy and nature beauty of Canada and people I started to get to know.

At that time, I only had two Shanghai Jiaotong university graduates I knew working in the city of Vancouver.

Instagram photos


I like to post some photos for the hiking trip. And also one video.

I like to take some break and think about how important it is to enjoy a Saturday, hold on my plan to work on mock interview, algorithm problem solving, pluralsight.com course responsive website etc.






One video - I like my voice


I talked to my roommate Emma and she said that my voice is not aging at all. I like my voice. Here is the video I recorded at the top of mountain with my friend Zhuang and all other families. I missed the fun.


Count down China vacation

April 7, 2018

Introduction


I will have a very short vacation to China this April 12 to April 18. This is the first time I made the choice to vacation in April.

First of all, we have get-together after 30 years, we graduated with applied mathematics from Shanghai Jiaotong university. We chose one week just after Shanghai Jiaotong University 122 years birthday April 6 celebration.

I spent a lot of time to read wechat group 500 people of Shanghai Jiaotong university just setup for Shanghai Jiaotong university 1988 graduated students. Suddenly, I had to challenge my memory to recall all those faces. I have no clue who they are. But once the pictures together with 30 years before/ after, my memory is coming back.

Life is such a beautiful thing with so many talent friends graduated in 1988 sharing the memory together using wechat.

Not all of us are huge success and very good career. We do have some of us to complain that they work for the big manufacture business, and went through the hard time to lose the stable job, and then the transition to the challenging life.

But we do have a lot of successful stories, in my class 70141, there are principal scientist, professors, deans of universities, math teacher and bankers one of 3600 banks in China top executive etc. We are lucky since we chose to study mathematics,  we had less than 30 people in the mathematics major in Shanghai Jiaotong university admitted in 1984. But at that time, we have more than 6 class of mechanical engineering major, material science major etc.




Friday, April 6, 2018

Leetcode 312: Burst balloons

April 6, 2018

Introduction


It is a hard level algorithm, so I like to work on the algorithm over ten times. I like to spend time to read this blog written in Chinese, and then try to understand better about the algorithm.

Here is the gist I created for blog study.

My favorite algorithm


It is the first time I read this analysis in Chinese. I could not believe that the analysis is such a good one.

I have to learn how to break into two subproblems and also two of them are independent.


Algorithm study: 95 algorithm videos (VV)

Algorithm study: 95 algorithm videos (VIIII)

Algorithm study: 95 algorithm videos (VIII)

Algorithm study: 95 algorithm videos (VII)

Algorithm study: 95 algorithm videos (VI)

Algorithm study: 95 algorithm videos (V)

Algorithm study: 95 algorithm videos (IV)

Algorithm study: 95 algorithm videos (III) - Leetcode 5: Longest palindromic

May 4, 2018

Introduction


It is six minutes teaching video for Leetcode longest palindromic substring. Here is the link.


Algorithm study: 95 algorithm videos (II)

April 20, 2018

Introduction


It is hard level algorithm called Leetcode 312: Burst Balloons. And the video is 20 minutes, I spent the time to watch the video, staying at home for one day vacation. I enjoyed the learning of the algorithm.

It is interesting for me to learn the dynamic programming through the video. I like to evaluate the author and see how good he is. I know that he is working for Facebook.

Leetcode 312: Burst Balloons


I like to talk about a screenshot and discuss the layout of dynamic programming algorithm presented by basksetwangcoding.



First step, I need to define state for the dynamic programming algorithm.

Next step, I need to define initialization step.

Third step, I need to define the function, problem and subproblem how to connect each other.

[left][right] = Max(i: [left + 1, right - 1])

For each subproblem, coin[i] * coin[left] * coin[right] + [left][i] + [i][right - 1]

Fourth step, I need to define result: [0][n - 1]

I need to put together a simple example to explain the solution to the peer. Here it is the example:

  1    2    3    4   5   6   7  8  9

Algorithm practice


Here is my C# practice.

Algorithm study: 95 algorithm videos (I)

April 6, 2018

Introduction


It is a hard level algorithm called Leetcode 312: Burst Balloons in Leetcode.com. I like to study the algorithm again by watching the teaching video here.

I could not believe that I finally have time to write code for the algorithm on April 25, 2018.

Leetcode 312: Burst Balloons Algorithm practice


I started to work on the algorithm on April 24, 2018. I have to learn the algorithm by working on a simple test case [3, 1, 5, 8] with the maximum value 167 based on Leetcode 312 problem statement. What I did is to write C# code based on the idea based on the video provided by a facebook engineer.

I calmed down and thought about how to write this dynamic programming solution, I told myself that I should take the time to think and do not rush, read other people's source code.

Basic ideas are simple. Define the base cases first, and then bottom up build the dynamic programming table.

I spent more than 40 minutes to write down the code on the paper. I put the code in Visual studio and debug the code. Apply the test case [3, 1, 5, 8]. But the code does not work, the value is much bigger than 167. Actually it is 218.

Here is my C# practice with some bugs. I need to figure out my problem in the algorithm. 

I could not believe that I could not count the correct number. The number is too big. In theory, it should be the error from the base case, the logic of recurrence is simple and I copied from the facebook engineer presented in the above video. But I need to train myself on this bug finding process. 


Find the bug


It is time for me to read discussion panel of Leetcode 312, I read a few of them, but the dynamic programming idea is different. So I continued to google and read a few blogs. One of blogs is very good since the blogger works for Microsoft.

But I still could not apply my case. The dynamic programming method in those blogs are inclusive, not exclusive.


Questioning the base case


Finally I started to question my base case, what is the value dp[i, i+1], in other words, keep ith and (i + 1)th balloon, then there is no balloon to burst. My answer is numbers[i] * numbers[i + 1], that is too much. So I changed to one. I ran the code still not the correct. So I finally know that it should be 0.

Although it takes me a lot of hours to learn the algorithm, but I think that I do right thing for myself.

Here is my C# code to pass Leetcode 312 online judge.

Thursday, April 5, 2018

Algorithm study: 95 algorithm videos

April 5, 2018

Introduction


It is very surprising that those videos are very well prepared by a facebook engineer in Chinese language. I really like to learn something from the teaching.

Here is the video feed. Here is the author's profile on leetcode.com.

10 most favorite algorithms


I like to choose my 10 most favorite algorithms and write down some notes here. I like to study some algorithms so that I can prepare some good questions to be a mock interviewer for a peer who prepares for Google phone interview second round.

I just could not believe that I had last 2 mock interviews as interviewer, and two peers are preparing for Google onsite in a week. I can tell how good they are to prepare for the interview.




Leetcode 84: Largest rectangle in histogram

April 5, 2018

Introduction


It is time for me to learn this hard level algorithm again. I know that it takes at least 10 practice for me to learn a hard level algorithm. Today I chose to study the video prepared by basketwangcoding in Chinese. My last practice was on January 18, 2018. Here is the blog.

30 minutes video lesson


I like to write down some notes from the lecture.

Brute force solution


In order to learn the algorithm very well this time, I like to work on the test case, [2, 4, 6, 5, 3], explain to myself how to solve the algorithm using O(n^2) brute force solution first.



How many rectangles to be calculated? What is the maximum rectangle area's value?


Iterate the end position from i = 0 to 4.

i = 0, the rectangle is 2.
i = 1, the rectangle is 4.
i = 2, the rectangle is 6.
i = 3, the rectangle is 5 + 5 = 10
i = 4, the rectangle is 3 + 3 + 3 + 3 = 12.

So the maximum rectangle is 12.

For each end index, we can go backward to search until the array's value is less than end index's value.

Or I also can think about the alternative idea. It is to iterate the start position from i = 0 to 4,

i = 0, the rectanlge is 2 + 2 + 2 + 2 + 2 = 10.
i = 1, the rectangle is 4 + 4 + 4 = 12.
i = 2, the rectangle is 6.
i = 3, the rectangle is 5
i = 4, the rectangle is 3



Being interviewer: Leetcode 250: Count univalue subtrees

April 5, 2018

Introduction


It is my favorite algorithm in March, 2018. I had two practices on this algorithm, one is to write the algorithm in 30 minutes mock interview, and the second one is to review the peer's practice. I chose the algorithm to interview the peer on April 4, 2018 10:00 PM, but I could not give out the solution based on the peer's code.

Follow up 


Here is the code I reviewed in mock interview. The peer asked my advice, but I could not tell at that time the code was bug free.

Now it is 9:20 PM April 5, 2018, I like to write a C# solution based on the simple idea, using negative to represent that the tree does not have same value. Here is my C# code.


Wednesday, April 4, 2018

2,000 Things You Should Know About C#

April 4, 2018

Introduction


I was asked in my mock interview as an interviewer a few days ago, what language I will use in mock interview. Python, Java, JavaScript are mainly choices. I chose to use C# language.

In order to learn C# better, I spent a few hours in the morning to go over items in basics catalog on 2,000 Things You Should Know About C#.

C# reading 


Here are the items I plan to study again. I like to learn C# even I am very busy. Just work on 2,000 things, work on a few items every day.





Pluralsight.com: Adobe muse building responsive single page website

April 4, 2018

Introduction

It is time for me to spend two hours to work on the course called: Adobe muse building responsive single page website.

Being interviewer: Leetcode 54: Spiral matrix print

April 4, 2018

Introduction


It is the algorithm for me to give the mock interviewee to work on back to Feb. 14, 2018. I just noticed that the interviewee joined the top software company MTN recently. So I spent time to replay the video and also wrote a C# practice based on his practice. It is very easy to tell from the video that the peer had very good problem solving skills.

Code review


Here is Java practice code I reviewed. I like to practice it using C# as well.



Feedback I gave


Here is the feedback I gave out on Feb. 14, 2018 after the mock interview. 


Tuesday, April 3, 2018

Leetcode 282: Expression Add Operators

April 3, 2018

Introduction


It is hard level algorithm. I like to study the algorithm so I searched the discussion panel. I found one link with very good comment, here is the link.


Code study


I like to prepare an algorithm for my 10:00 PM mock interview as an interviewer. I like to try a new algorithm, and also I like to learn quickly through the mock interview as well. Now it is 9:29 PM.

First, I have to understand how to handle multiplication. Here is the link to give out the explanation.

If you want to add a * between 3 and 4, you would take 3 as the digit to be multiplied, so you want to take it out from the existing eval. You have 1 + 2 + 3 * 4 and the eval now is (1 + 2 + 3) - 3 + (3 * 4).


Pluralsight.com: Building angularJS and node.js apps with the MEAN stack

April 3, 2018

Introduction


I plan to spend 4 hours to study the course called Building angularJS and node.js apps with the MEAN stack.

Leetcode 76: Minimum windows substring

April 3, 2018

Introduction


It is the hard level algorithm. I have practiced similar algorithm on mock interview platform over 5 times last 12 months.

Code review


Here is C# practice I did based on one of discussion.


Leetcode 587 Erect the fence

April 3, 2018

Introduction


It is hard level algorithm related to sweep line algorithm. I plan to work on this algorithm called Erect the fence.

Monday, April 2, 2018

Being interviewer: Leetcode 56: Merge intervals

April 2, 2018

Introduction


It is my mock interview's algorithm called Leetcode 56: Merge intervals. I asked the peer to work on the algorithm by mistake, I like to ask him to work on Meeting Room II.

Algorithm analysis


The peer worked very hard and he gave his analysis for the algorithm. Here is the analysis.

One thing I really like to share is that the peer can write the perfect analysis without any issue in his writing.

The reason the peer can pass code screen and get phone screen of Google, I believe that he definitely has very good analytical skills.



Being an interviewer: BST successor search

April 2, 2018

Introduction


It was my 10:00 PM mock interview. I had chance to discuss with the peer about his algorithm BST successor search. He wrote the program using JavaScript.

We spent extra time to discuss the algorithm, and we ended up the discussion around 12:40 AM. I spent 2 hours 40 minutes discussion with the peer. The peer is very talent and he is preparing Google phone screen.

I like that the peer can write very clearly for the algorithm analysis. This is the first time I worked with a peer to write so clearly and also very accurate.


Code review 


I also helped to review the peer's Javascript code. I also learned a few things about JavaScript.



Leetcode 253: Meeting room II

April 2, 2018

Introduction


It is 10:00 PM mock interview. I had chance to work on Sudoku solver. And after the mock interview, I had discussion with the peer about algorithms Meeting room II.

We had discussion about the algorithm around 20 minutes.

Algorithm analysis


Here is the analysis the peer gave in mock interview.

I also like to follow up after mock interview, I found similar idea in Leetcode discussion. Here is the link.



Follow up 


April 3, 2018

I reviewed the code written in C# language using line sweep algorithm. Here is the C# practice.

Also I like to read the book chapter 30: Sweep line algorithms. I did first time to learn the algorithm called Andrew's algorithm, also called Andrew's monotone chain convex hull algorithm. I also found a hard level algorithm to practice and apply the Andrew's algorithm, which is called Leetcode 587 Erect the fence.



Sudoku solver

April 2, 2018

Introduction


It is such great experience to work on Sudoku solver in mock interview. I wrote the algorithm in less than 30 minutes.

Code review


Here is my analysis with C# code.


Sunday, April 1, 2018

Leetcode 277: Find the celebrity

April 1, 2018

Plan to work on the algorithm Leetcode 277: Find the celebrity. Let me think about 10 - 15 minutes first.


Leetcode 261: Graph valid tree

April 1, 2018

Introduction

I like to read a few blogs about Leetcode 261: Graph valid tree.

Leetcode 151: reverse words in a string

April 1, 2018

Plan to read discussion panel and vote 10 ideas.


Leetcode 139: Word break

April 1, 2018

I am planning to study Leetcode 139: word break algorithm again. I like to read discussion panel and vote at least 3 ideas.



How to be a good interviewer?

April 1, 2018

Introduction


I like to do a small research how to be a good interviewer. I learn to be an interviewer by myself, I got a bad feedback when I mock interviewed a person anonymously no video from Singapore with over 6 years experience a few days ago. I gave the algorithm called Leetcode 152: Maximum subarray product. Because I did not want to give all hints out to solve the problem, the interviewee wrote an idea with so buggy code using checking negative elements. At the end of 45 minutes, both of us did not learn anything. The interviewee did not learn anything from the mock interview, I also got bad feedback.

So in order to make mock interview learning experience, I choose to give out all hints and sometimes I make it a tutoring session.

Deletion distance


On March 31, 2018, I gave the peer a mock interview using deletion distance. So I decided to step in and worked on the algorithm together, discussed how to approach the dynamic programming algorithm together.





Friday, March 30, 2018

Being interviewee: Island count

March 30, 2018

Introduction


It is my mock interview algorithm at 12:00 PM. I spent 17 minutes to write the algorithm. I learned a few lessons through the mock interview.

Mock interview performance


I was lazy and do not declare two variables visitRow and visitCol, and then I mix startRow with visiitRow, startCol with visitCol. I wrote the code and forgot to push four neighbors into queue, I pushed startRow, startCol to the queue instead.

I fixed the issue when I did white board testing. I finished the coding in less than 17 minutes, and I failed 3 test cases. It took me one minute to find the bug from line 47 to line 50. I fixed it in less than one minute.

Next time it is important to declare new variables for visitRow, visitCol, otherwise I may mix things together. Build a good habit.

Here is my C# code.

Here is my last practice five days ago.

I enjoy to write code using BFS and also using queue. It is fun and it is easy to make mistakes. But with more practice, I will be more comfortable to think using BFS.



Yichun city house research

March 30, 2018

Introduction


It is not too hard to do research on house market in the city of Yichun, my home town. As a software programmer, I have to learn to apply my research ability in data structure and algorithm to a real world.

One of my projects is to find a small condo to purchase when I take a vacation back to China from April 12 to April 18.

Here is the project near the place I grow up, my sisters living there are physicians and teachers.

$20,000 Canadian dollar 1 bedroom/ 1 bath condo


I like to look into pengshen gold collar condo. Here is the website link.


Saturday 10:00 AM mock interview

March 30, 2018

Introduction


Life is tough. The first time I met a peer from New York, he setup his laptop inside the car and then we had a short discussion about mock interview. It is his first mock interview. He told me that he mainly worked on Java, he is looking for a job. He does not have interesting in algorithm and data structure. He worked on a few startups before.

I was told to work on my algorithm first. I spent five minutes to explain the idea how to solve recursive problem called minimum sales path. How to think about recursively? Explain the root node, check its value, and if there are no children, then return its value; otherwise get all its children, ask them to solve the problem, and get the minimum value from those paths.

The peer asked me how often I solve the problem. Do I do other things? I explained a few things:

// leetcode - hackerrank contest /
// stackexchange.com /
// frontendmasters.com - take courses -
// pluralsight.com - 4700 courses -
// C# - html, css, jquery, javascript, at work - learn new technology - angular JS - react framework,

My review for the peer


The video was cut after 15 minutes. I chose not to write any code, I just used my own words to explain the algorithm first. And then we had short discussion about the algorithm and how to learn things in general.

I left the feedback. I wrote in less than 5 minutes.

I was touched by your hard working spirit. Please do not get frustrated to look for a job, specially a programmer job. I used to work in USA with different jobs and experienced difference emotions as a software programmer, student. 

I think that it is good decision to go back to study data structure and algorithm foundation. It also helps me to focus on the foundation. If you like to learn how to do problem solving, in data structure and algorithm, and know how people work hard on that. You will find that the job you are doing, looking for doing is much easy compared to this part. 

You set up everything working inside the car for the mock interview and sit in the driver seat. That is so amazing. 

Trust hard word. Word hard. I write coding blog to encourage others to work hard. Do not get frustrated. 

Actionable Items


As a software programmer, I learn to respect people around me how hard they are working. If you do like to be a software programmer, you have to sacrifice and learn how to work with people. Help them make money. 

As we know, there are high pay jobs from top software companies, we as a software engineer can work hard for. But we all know that it is so hard to achieve, most of us cannot make it. 

We have to think about more how to make money outside the job, and then stay in software engineering field and keep doing our loved jobs as a programmer. Love the job you are working on, try to bring in more things to your career; enrich your own life with hard work. 

Find pairs and keep the order specified by the original array

March 30, 2018

Introduction


It is my mock interview algorithm. I wrote a solution but I did not meet the requirement of specified order. I need to rewrite another one after mock interview.

Code review


Here is the C# practice I wrote in mock interview.

Thursday, March 29, 2018

Being interviewer: Deletion distance

March 29, 2018

Introduction


It is the dynamic programming algorithm called deletion distance. I had a 12:00 PM mock interview. I had chance to discuss with the peer how to solve the problem by playing with dynamic programming table.

How to build a dynamic programming table?


Here are a few things we discussed.

1. How to define rows and columns?
2. Add "" string for row and column
3. First time I found out that I need to add extra row/ column to identify current char to work on.
Line 19 is extra row added to show current char to work on, first char next to line 23 to line 26 is the extra column added to show current char to work on in another string.

4. I worked on the first row and first column, and then I did write line 29 to line 33 to explain the recurrence formula.

5. I asked the peer to work on the second row. He worked on second row and third row, he made a mistake to calculate distance("fro", "do"). And then I asked him to check diagonal value dist("fr","d") = 3.

We then had discussion how to prove that the minimum distance is the diagonal value when the current char is the same as the other string's current char.

The proof is from line 25 to line 36. I explained that the matrix or dynamic programming two dimension table from left to right, top to down, it is not descending order. So it is easy to prove that based on the fact.


Giving advice


I also wrote some advice for senior developers to pick up algorithm and data structure in general, specially on deletion distance algorithm:

Do not feel frustrated. I also make a lot of mistakes and practice a lot of times on this algorithm. Practice more. Learn one thing a time.

I do not need to find out how good you can write code. Try to play with setting up a two dimensional table first, and then write code based on the steps. It may take a few times. Once you get a lot of practice, dynamic programming should be very mathematical, use a template, it is easy to write the code.

Being an interviewer: Pancake sort

March 29, 2018

Introduction


It is my interesting thing to learn how to be a good interviewer. Since I was so patient and also gave some advice like "write readable code" and "write simple code", I ended up knowing that a very competitive programmer with so many medals on hackerrank, and my favorite codeforce.com, the expert competitor.

Code review


Here is the C++ code I reviewed. Most of time the peer worked on the problem related to const in C++. The flip function change cannot be done in place, we debugged the code and found the issue.


Being interviewee: Array of array products

March 29, 2018

Introduction


It is my algorithm to write in the mock interview. I remembered that I have to work on one multiplication from left to right iteration using dynamic programming, and then two multiplications from right to left calculation.

I have to learn again to write a correct solution in less than 10 minutes. This time I spent 18 minutes, and also I got a hint from the peer. The peer told me to define a variable leftToRight to save product of array elements on line 18, and also switch the order of line 22 and 24 to assign the value first, and then do the multiplication next.

Code review


Here is my C# practice.


Being interviewee: Leetcode 10: regular expression matching

March 29, 2018

Introduction


It is my sick day. I have to stay at home. Yesterday I noticed that my nose was running and made sneeze, one of coworkers asked me if I was sick. I told her that I had allergic. But I had to honestly admit that I had a cold, I could not go to work and stay at home.

I had 10:00 AM mock interview, I had to work on Leetcode 10: regular expression matching algorithm. I spent 34 minutes to write analysis and code, I fixed a few bugs to pass all test cases.

Code review


Here is my analysis and C# code.

I like to write down my misunderstanding in my first writing, and then how I fixed the bug through the white box testing and web compiler.

For example, to build a dynamic programming table, I have to work on "b", "b*".

                    ""  "b"   "*"
                    ""  "b"   "b*"  - pattern
              --------------------
""    ""         T     F      T
"b" "b"        F     T      T

In order to calculate dp[row, col], I need to find the text char and pattern char first, and then work on current char only.

Highlights of bug fix after first writing in mock interview:

1. I did white box testing, need to fix the bug using test case "" matches pattern string "a*b*". I added line 21 to line 33.
2. web compiler runs the test cases. I failed most of test cases.
I noticed that I could not memorize the solution. I need to work on the solution itself.
I fixed line 25 checking pChar == '*' instead of checking pChar and its next char.
3. line 40, check pChar is '*' instead of checking next char is '*'.
4. line 46, col - 1 instead of col - 2 which causes index out of range error.

Dynamic programming quote


Today's quote on dynamic programming. I think that I learn something from today's practice.

Work on dynamic programming, do not worry about next char. Work on current char only. 

Best medicine to cure my cold


Here is the feedback I got from the peer. It helps me to recover from my cold. Actually the peer is very competitive programmer on codeforece.com, expert with contest rating: 17xxx ( max: expert, 1886), competitive, also on hackerrank.com with 5 gold medal.

One more practice


I knew that I was sick with a cold, and then I felt some nervous in mock interview. It is hard to write a dynamic programming solution in less than 30 minutes.

I knew that something will go wrong. To learn a hard level algorithm, I have to be so patient and let myself make mistake first; and then find the ways to fix it in mock interview, and also in less than 30 minutes.

First of all, I mixed the dynamic programming solution with recursive solution. Since my last practice I spent over 40 minutes to write a recursive solution in mock interview to play with a friend less than one month ago. I look ahead for star pattern, current char is a - z, I check if next char is star. But it is wrong to do that in dynamic programming, mix current problem with next problem.

Dynamic programming is to work on the current problem and use subproblems cache results.



Sick day

March 29, 2018

Introduction


It is my sick day. I have not had a cold long time. Usually I play a lot of hours tennis sports and swimming, I stay healthy. But this time I got my nose running, and then I have to call a sick day, stay at home, plan to do something to help me recover.

Sick day Thursday


I need to find ideas to recover quickly.

Natural flu treatment: 9 proven flue busters.

Yichun city real estate research

March 29, 2018

Introduction


It is the learning experience to be a responsible adult. I like a lot of things, like shopping, clothing, but somehow I do not spend enough time to do research on the city I grow up called Yichun city.


Year 2007


I spent over one month to stay in the city of Yichun, at that time, I was young and naive. I knew that life is not easy. I lived with my mom and my sister and stayed in a home near the center of the city. At that time, my sister is a teacher of Yichun university. I learned something from her since she works full time as a teacher. She never needs to worry about job security, visa status and American dream.

At that time, she argued with me that the home price will not go up since cross street high-rise building $1000 RMB/ square meter.

At that my 401 K in USA can afford to buy two 2 bedroom condos in 2007. I was not satisfied but I did not purchase anything in my hometown. Now it is $3000 - $8000 RMB/ square meter.

After 10 years, my 401 K do not do very well, since I sold everything in high risk fund and changed to stable fund in 15 years low back in 2009.

Real estate research


It is time for me to do some research. Always stay positive. Keep good faith on what I have. No matter how little I have, try to use it as bible teaching.

Hebrews 13:5

Keep your lives free from the love of money and be content with what you have, because God has said, “Never will I leave you; never will I forsake you.”




Wednesday, March 28, 2018

Being an interviewer: Root of a number

March 28, 2018

Introduction


It is a binary search algorithm called root of a number. The hint I gave in the mock interview as an interviewer is to explain how many numbers to search for x = 8, n = 3, it is from 0, incremented by 0.001 to 8, total is 8000 numbers to search.

Binary search algorithm


Here is the binary search algorithm I reviewed written by the peer. The algorithm still has issues to pass a few test cases. I like to look into as well.

I like to get organized and review all my past practice.

Code review


Actually the code should be updated in two places:
1. Line 44 and 45, return (double) m/ 1000;
2. Line 56, return (double) s/ 1000;

The argument is that when s == e on line 37, the return value should be s, not -1 or 0.0.

Incremental value 


It is better to change the design, and use 0.0001 as a different number to apply binary search. Here is C# code.

Given the example x = 8, n = 3, instead of search 8000 numbers, we choose to search 80,000 using binary search. Incremental value is 0.0001 instead of 0.001.

Being an interviewer, it takes some time to figure out how to guide the peer to lead the optimal solution and pass all test cases.

Work count practice

March 28, 2018

Introduction


It is very challenge algorithm to work on in 30 minutes. I have worked on the algorithm more than 6 times, but I never had chance to complete the code and pass all test cases in less than 30 minutes.

Today I also read the problem statement, I need to write code to keep the original order of words in the same bucket.

Code practice


Here is the C# code I wrote in 30 minutes in the mock interview. After the mock interview, I spent at least 30 minutes to complete the code and pass all test cases. Here is the C# code to pass all test cases.

Here are highlights of my work after mock interview:

1. line 18, Punctuation chars: "., !:;?", I missed :, ;, ?
2. line 22, Add function argument totalCount
3. line 22, function argument should be replaced, not orignal string document.
4. line 27 - line 41, I fail to call string.Replace to replace ' using empty char, so replaceChar function is written.
5. comment out line 16
6. Still confuse ToLower() function call, should string.ToLower() or document.ToLower()
Argument: string is class, not an interface, so ToLower is member function of string class, not interface member function.
7, line 57 and line 58, index variable should be used instead of using variable i defined on line 49.

2,000 Things You Should Know About C#

March 28, 2018

Introduction


It is time for me to slow down to practice data structure and algorithm, and think about how to advance myself as  a C# programmer. One thing I like to do is to learn something quickly. I spent over one hour today to study interface from 2,000 things you should know about C#.

Interface




  • #434 – Interfaces
  • #435 – Implementing an Interface
  • #436 – The Implementation of an Interface Can Be a Subset of the Class
  • #437 – Access Interface Members through an Interface Variable
  • #438 – Benefits of Using Interfaces
  • #440 – A Class Can Implement More than One Interface
  • #441 – Implementing Interface Members Explicitly
  • #442 – Explicit Interface Implementation Allows Duplicate Member Names
  • #443 – An Interface Cannot Contain Fields
  • #444 – Interfaces Can Inherit from Other Interfaces
  • #445 – Differences Between an Interface and an Abstract Class
  • #446 – Deciding Between an Abstract Class and an Interface
  • #447 – Use as Operator to Get At an Object’s Interfaces
  • #448 – Use the is Operator to See if an Object Implements an Interface
  • #449 – You Can Pass an Interface Variable to a Method
  • #450 – Interfaces Should Normally Start with the Letter ‘I’
  • #451 – Implement Interface Explicitly to Simplify How a Class Appears to Clients
  • #454 – Return an Interface as a Return Value from a Method
  • #455 – Define an Interface Based on Existing Members of a Class
  • #456 – Explicitly Implemented Interface Members Are Automatically Private
  • #536 – Using a Generic Interface
  • #537 – Implement a Generic Interface with a Generic Class
  • #612 – Members of an Interface Are Implicitly Public
  • #613 – Interfaces Cannot Contain Static Members
  • #647 – A struct Can Implement an Interface
  • #799 – Interface Members Are Implicitly Public
  • #1,067 – Covariance and Generic Interfaces
  • #1,068 – Generic IEnumerable Interface Is Covariant
  • #1,069 – Contravariance and Generic Interfaces


  • It will take me 2 hours to go over those items.

    Tuesday, March 27, 2018

    Book reading: Competitive Programmer's Handbook

    March 27, 2018

    Introduction


    It is my 10:00 pm mock interview as an interviewer. I never expected that I will interview a senior who will prepare Google onsite in 3 weeks. So I did ask two algorithms I studied today, and then I was so surprised to learn how good the peer gave his analysis, and also I learned the algorithm from his analysis.

    I was told to read the book called: Competitive programmer's handbook by Antti Laaksoen, Draft December 10, 2017.

    Advice from the peer


    1. read Competitive Programmer's Handbook
    2. 200+ on leetcode  - top 100 question
    2.1 strong at DP - don't have to solve every DP
    2.2 graphs -> open that topic and solve medium and hards

    3. 10 minutes to solve a question -> look up the best solution for this problem -> don't code it immediately -> wait 2-3 days at least

    Sort k shifted array

    March 27, 2018

    Introduction


    It is the sort algorithm and I cannot use heap since C# does not have class. I write a function to find the minimum index in K + 1 contiguous subarray.

    Algorithm practice


    Here is my C# practice.


    Leetcode 745. Prefix and Suffix Search

    March 27, 2018

    Plan to work on this hard level algorithm Leetcode 745: Prefix and suffix search.

    Leetcode 211. Add and Search Word - Data structure design

    March 27, 2018

    I am planning to work on this medium level algorithm in short future. I like to work on the algorithm and think about 10 - 15 minutes first.


    Leetcode 152: Maximum product subarray

    March 27, 2018

    Introduction


    I like to work on this algorithm Leetcode 152: Maximum product subarray, and I find that it is similar to the algorithm I practice so many times called float numbers and operators.

    Algorithm practice as an interviewer


    I chose the algorithm to interview the peer in mock interview. The peer is very talent programmer, he had a facebook onsite last December, and he prepares for Google onsite. what I found out is that he needs some hint to come out dynamic programming solution, but his coding ability is very strong, and also the analysis ability.

    Here is the transcript.



    Facebook interview algorithms

    March 27, 2018

    Introduction


    There is very organized folder on the github with over 70 algorithms. I plan to study those algorithms one by one. Here is the link. The title is called facebook interview algorithms. The author studied those algorithm to prepare facebook intern from August 2016 to March 2017, and the source is from 1point3acres.com.


    70 algorithms


    I plan to work on over 70 facebook interview algorithms. That is a lot of algorithms to work on.

    I learn from my mock interview experience, only 30 algorithms. I have practiced those 30 algorithm over 7 rounds.






    Being interviewer: Leetcode 253: Meeting rooms II

    March 27, 2018

    Introduction


    It is a medium level algorithm. I spent over 30 minutes to read a few blogs related to the algorithm. I feel that it is very interesting algorithm, I like to spend more time and write the algorithm as well.

    Algorithm study


    It is so much fun to study the algorithm. There are a few solutions but Leetcode does not have public discussion for the algorithm. So I like to practice a few solutions.



    Actionable Items


    I asked the question on the mock interview on March 27, 2018 10:00 PM. The peer gave me the solution and I was told to work on line sweep algorithm. Here is the analysis.

    I just could not believe that the peer worked on the algorithm before, but he has very good understanding of the algorithm.


    Monday, March 26, 2018

    Find two items with given sum in the array

    March 26, 2018

    Introduction


    It is another 10:00 PM mock interview. I do not pay special attention, but I got a review about things to work on. I think that the feedback is very helpful, so I like to share here.


    Code practice


    Here is my C# code practice.

    Here is my feedback. I need to learn to speak slowly.