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.



    Being an interviewer: Leetcode 250: Count univalue subtrees

    March 26, 2018

    Introduction


    I like to learn to be a good code reviewer. Sometimes I practice with a friend a few times, I start to learn how to help the peer to give some code review.

    Code review


    I spent over 60 minutes to work on the algorithm, the peer gave me very good advice how to make improvement. So I also like to work hard and give some code review.

    I will document my code review here as well.


    Here is the Java code I got from the peer and then I cleaned up test cases and analysis of the algorithm.

    Here is my code review:

    isUnivalTree function


    You can simplify the function isUnivalTree using one statement, please see attached image of the highlight of your code:




    Here is my advise how to write in one statement instead. I will explain why I like to do that.



    The argument is this, left && right is not true, you do not need to check root value compared to left child value if there is one. So your logic includes redundant work. 


    checkSize function


    There are a few issues on checkSize API,



    1. First the return type does not match API definition, people will surprise to get a return Node when the function name is called checkSize. You should return size instead of a Node. Why we need a Node, where to find the size in the Node object. 

    Also the function name checkSize is not meaningful, it is better to call calculateUnivalSubtreeCount. 

    2. Second, you have a giant expression I circled using red color. It is better to avoid negative checking. Think about default value, and then write a positive checking. 

      Here is the code I think with better presentation:


    Clean up is a small good thing to do


    I also like to point out that it is good habit to clean up document before sharing with others. Remove extra space, unrelated comment, and make the code clean and readable. Once you do it in every mock interview, you will start to learn how to act quickly. You will apply the habit to the work and also in the official interview.

    Working hard does not mean staying up 1 AM or 2 AM. It takes time to build up good knowledge of data structure and algorithm. But builing a good habit just takes determination and good mind of making smart choice, that is my thinking. Hopefully I can bring your attention to the issue.

    Leetcode 765. Couples Holding Hands

    March 26, 2018

    Introduction


    I like to work on this hard level algorithm called Leetcode 765: Couples holding hands.

    Leetcode 41: Find missing positive

    March 26, 2018

    Introduction


    I like to get organized on those mock interview algorithm. One algorithm is called Find first nonnegative integer in the array, I went over the practice and added the label. Also I found out that I need to work on the hard level algorithm Leetcode 41: Find missing positive.

    It is my idea to practice 10 ideas based on Leetcode discussion in order to learn a hard level algorithm.


    Find first missing nonnegative number

    March 26, 2018

    Introduction


    It is the algorithm to find first missing nonnegative number in the array. What I like the algorithm is to work with the constraint. The constraint is that the array cannot be modified, and then second algorithm is to modify the array.

    Code review


    I like to work on the algorithm one more time. Here is my C# practice for the first solution without changing the input array. And here is the second solution to change the input array.

    Actionable Items


    Google and find algorithms in Leetcode related to the algorithm.


    Being interviewer: Longest Arithmetic Progression Algorithm

    March 26, 2018

    Introduction


    I like to learn the algorithm by asking the interviewee to solve the problem. I had a mock interview on March 25, 2018, so I had chance to work on the algorithm over 30 minutes.

    Mock interview


    Here is the mock interview discussion I had with the peer.


    Leetcode 250: Count univalue subtrees

    March 26, 2018

    Introduction


    It is a medium level algorithm. I was asked to solve the algorithm in the mock on March 25, 2018. So I had chance to learn from the peer.

    Code review 


    Here is my C# code. I got the idea to solve the problem since I studied another tree algorithm
    Leetcode 230Kth Smallest Element in a BST on March 23, 2018.

    Being interviewee: Leetcode 250: Count univalue subtrees

    March 26, 2018

    Introduction


    It was my algorithm called Leetcode 250: Count univalue subtrees.

    My practice


    First I was asked to work on the function to check if binary tree has same value. And then I was told to work on the algorithm to count univalue subtrees.

    Here is my practice.

    I came out the working solutions for both algorithms. But the first one the peer told me to simplify the algorithm. I do not need to use extra two arguments: hasDefaultValue, defaultValue.

    I spent 28 minutes from 9:18 PM to 9:46pm to work on the first algorithm, including discussion with the peer. And I spent 41 minutes to work on the second algorithm, and also had a discussion with the peer on different test cases.


    Sunday, March 25, 2018

    Yichun city - my home town

    March 25, 2018

    Introduction


    It is my Sunday afternoon research. I need to find something to work on related to my China vacation trip. I only have 8 days trip include one round trip more than 22 hours on the plane. I budget to spend $800 Yuan on fastest train round trip from Shanghai to Yichun to visit my family in the city of Yichun.

    House research


    I could not believe that I could not afford more than 40 square meter place to purchase. I like to find a place to purchase so that I can do some business in my life as an educator in my own home town. I like to do something if I like to do it.

    Here is the article I like to read about the city of Yichun.

    One more research


    Here is something I like to study. The cost to do the work inside the home.


    Island count

    March 25, 2018

    Introduction


    It is my mock interview algorithm called Island count. I was so excited to work with a peer who is from Israel this morning 10:00 AM. The peer told me that it is better to write an iterative solution.

    Code review


    I had to follow the advise from the peer, and then I decided to write a queue to apply breadth first search to visit neighbors, mark visited.

    Here is my C# code passing all test cases.

    The instruction to play mock interview nicely


    I have worked on this algorithm so many times. I know how to train myself one more time nice and easy, get more experience how to write readable code, practice one more time to explain the algorithm and talk about ideas with a peer.

    First few minutes, I will write down the matrix using example 5 x 5 matrix, and go over row by row from left to right starting from position (0, 0). If I find the first one, I will mark it visited, and then use DFS/ BFS to visit all neighbors as elements in the same island. I will increment island count variable one. I will mark the first island using char 'A', next island using 'B', likewise. I will apply the same analysis twice, using -1 to mark first two islands A and B, and then just quickly apply C, D, E, F for the rest of islands.

    After that, I will ask the peer's advice to choose DFS or BFS. Give him/ her a choice, and follow  the advice. I am willing to write any solution, but I do not want to stick on one solution, I like to practice any solution if need.

    This time the peer told me that I should not use recursive function, it is written to write iterative solution in mock interview platform for interviewer. So I have to follow the advice, decide to write the iterative solution.

    I thought about using for loops, and then decided to write a queue. Since it is the only way I can apply BFS without using recursive function, otherwise I cannot handle the neighbors just using loops. Data structure queue is definitely needed.

    Beautiful code


    It is not tough for me to write readable code using Queue, and apply BFS algorithm. I have practiced similar algorithm so many times last 12 months.

    I learn how to write readable code last 18 months.

    Give credit to the code reviewer, here is the link.

    Here is the blog about my past practice. I need to get organized and then I can review what each my past practice and see how good I am getting.


    Road trip to Vancouver island

    March 25, 2018

    Introduction


    I got an invitation to have a road trip to Vancouver island with my two classmates back in Shanghai Jiaotong university from 1984 to 1988, the trip was on Sunday from 7:00 Am to 6:00 PM from the city of Surrey to Vancouver island Victoria, Butcher garden.

    Here is the instagram link.

    China trip from April 12 to April 18, 2018

    March 25, 2018

    Introduction


    It is time for me to write something for my coming China trip from April 12, 2018 to April 18, 2018. It is so difficult for me to make a decision, the get-together of Shanghai Jiaotong university applied math major class from 1984 to 1988. 70141 is the name of class for around 30 students at that time.

    How to make a decision for the trip?


    I had two classmates who will fly from USA and Canada to Shanghai on April 12, 2018. One of my classmate who is a PH.D. graduate from California, I have not seen her over 30 years, she asked me why I could not join the meetup.

    I checked the calendar and also airline ticket by Air Canada, 12 hours direct flight, from April 12 to April 15 is $570 Canadian dollars. No matter what happens, I should be able to take April 12 Thursday off, Friday off, and then come back next Monday. Later, I decide to take two more extra days since the ticket price is same until Wednesday April 18. After April 18, the airline ticket is above $850 Canadian dollars.

    How to plan for the China vacation only for 8 days? 



    What makes one person success financially?

    March 25, 2018

    Introduction


    I graduated from top university from China called Shanghai Jiaotong university. When we were in the second year, 1985, there is a new classmate who joined us, his name is Neil Sheng, now he is top 100 ranking richest people in China. I had so many successful stories to tell from my classmates or friends back in Shanghai Jiaotong University or Florida Atlantic university.

    It is fun to write a small research topic and spend some time to think about. Life is such a great teacher. If you treat your neighbor, friends, classmate nice, you will have so many lessons to learn as an adult. I will share my person stories and will make this Sunday more meaningful.

    What makes one person successful financially?


    I have five siblings, and also I was told so many stories from my siblings. How hard they work as a teacher, physician, or a small business owner.

    I have friends to visit me from California, the young successful couple both with Ph.D. degree, they visited my home in the city of Vancouver in 2017. And she told me that she got 3 offers in one month in California. I was so surprised that the huge difference in the corporate world later on.

    Last week I had a friend who visited me as well. She told me another successful story. She chose to stay in Shanghai and had a very successful career, and took care of her parents last 20 years. And she shared with me a story about how good it is to obey your parents and respect your parents, give back to your parents, similar to Christian testimony. Since she is a good daughter and she likes to take care of aging parents, she bought a home over 15 years ago to let her parents living close to her. She does not like to stay in the same house with parents. That one good deed helps us to gain over 5 million Chinese dollars alone in the capital gain over 15 years.

    I offered her a road trip to visit the city of Seattle since I plan to have a vacation to Seattle. I did drive her in 2007 from New York to Boston, and we visited Yale, Harvard and MIT universities. At that time, she was planning to find a university for her daughter.

    Struggle is fun and meaningful

    Ephesians 6:2 Honor your mother and father.




    Being interviewer: Sudoku solver

    March 25, 2018

    Introduction


    It is such great experience to work with a software engineer from Israel 10:00 am mock interview.  The peer also told me that she works for one of top four software company in the world. She worked on Sudoku solver.

    As an interviewer, I like to write down some highlights for my code review.

    Code review


    Here is the solution I reviewed. First of all, the peer wrote down the analysis very clearly and asked me if I followed her idea after she wrote some of the code from line 21 to 44. After she wrote the solution to call recursive for next iteration, she asked me the feedback.

    Highlights of my code review:

    1. line 25 to line 26, I added those two lines. I explained that there is a bug to find next position of '.' char. Line 23, I changed column = j to column = 0, and add line 25 and line 26 to start from (i, j).

    2. line 56, I explained to the peer that no need to check, HashSet.Remove can handle the case if the char is not in hashset.

    3. line 88 to 91, I explained to the peer why backtracking is necessary. Her argument is that next iteration the element will be replaced by the available number. And then I gave her the example, first row with first two elements 5 and 3, and 3 empty space with '.', if we work on the third '.' and try the last available number but fails, we need to put '.' back and then continue to work on second '.'. Recover the original status.

    Using graph like the following:
    5 3 _  _   _
                  _ fail ->'.', work on third dot, (0, 4)
              next iteration to work on second '.'

    4. work on nextRow and nextCol calculation. Originally the peer wrote (emptyRow + 1)% n, (emptyColumn + 1) %m,


    Actionable Items


    It is very good to work with the peer on this algorithm. Today is Sunday. I choose to stay at home and work on mock interview. Yesterday I spent over 90 minutes to work with a peer on budget cap calculation. Later I talked to my roommate Emma, she told me that I have to think for other people. If I meet  a strong player on algorithm and data structure, I will talk over 90 minutes. Think about the other way, same applies to the peer I met as well.

    Emma is a very good IELTS teacher, and she told me to work on cleaning the living room table together. What I did is to learn and stay organized. We both laughed about the shopping I did in Seattle, and I did make a mistake to purchase too many Nike shoes for myself. I bought 3 pairs of Nike shoes, one pair I wore two days, it broke my skin near my ankle. I went to Seattle with my friend from Shanghai, she laughed about me how I can wear 3 pairs of sneakers. It turned out not cheap for 3 pairs of shoes, $150 Canadian dollars.

    Saturday, March 24, 2018

    Leetcode 734: Sentence similarity

    March 24, 2018

    Plan to work on the algorithm called Sentence similarity, easy level question. I like to study the blog related to this algorithm, the link is here.


    Being interviewer: Find new cap value

    March 24, 2018

    Introduction


    It is my favorite algorithm to find the cap value to fit into new budget. Today I also had chance to share the idea how to solve the problem using depth first search, dynamic programming method. Also it is so interesting to learn from the peer's failure. His idea is to use average function to determine the cap value, which failed two test cases.

    Algorithm analysis


    It is the learning experience for me to share the idea how to solve the problem. I like to learn the algorithm very well, one way to do it is to go through the experience as an interviewee. Find out what kind of concern the peer has, and help him to develop a solution in less than 60 minutes.

    I was very patient and spent extra 30 minutes to stay in the interview.

    Here is the analysis between two peers in mock interview 12:00 PM.


    Being interviewer: Find minimum path sum from root node to leaf node in tree

    March 24, 2018

    Introduction


    It is such great learning experience to be an interviewer. I had chance to learn from the peer to solve the algorithm called Find minimum path sum from root node to leaf node in tree. I just could not believe that he wrote so clear in the analysis based on breadth first search using a queue. I also like to learn Python from 30 minutes interview, I just copied what he wrote on the paper, and then asked a few questions later on.

    Code review


    The peer came out the idea to prune the algorithm, if there is a minimum path sum, then it can be used to prune the path by checking current path's sum value.

    It is long time for me to think breadth first search using Python, I had chance to learn how to write Python queue. Basically in Python there is no queue class, we have to specify to insert in the front using insert function, and then pop function from the end.

    Here is the python code.


    Largest smaller value in binary search tree

    March 24, 2018

    Introduction


    It is still very challenging problem after I work on the algorithm more than 5 times. I enjoy the talk about the algorithm. Actually I have more understanding about O(n) time in order traversal after I work on this algorithm called Largest smaller value in binary search tree.


    Mock interview practice


    Here is my C# practice.



    Sorting algorithm

    March 24, 2018

    Introduction


    I had two days vacation and also had a friend visiting from Shanghai. I just came back to work on mock interview, I had some difficulty time to run whiteboard testing, and then need some time to fix the bug.

    Code review


    Here is my C# code to pass all test cases. I made two mistakes in my first writing, and then I had issues to pass all test cases. I found the problem on line 15 and add line 20.


    Being an interviewer: Leetcode 54: Spiral matrix

    March 24, 2018

    Introduction


    I spent time to work with the peer on the algorithm called Leetcode 54: Spiral matrix on Feb. 5, 2018. It is time for me to review the Java code and figure out what to learn from the peer.

    Code review


    One thing is sure that the peer has much more competitive status compared to me in terms of career. I like to review the Java code and later on I will find something to work on.

    Here is Java code. What I have to do is to replay the audio and get context of the interview. The presentation of code looks like missing something.






    Being interviewer: Leetcode 54: Spiral matrix

    March 24, 2018

    Introduction


    One thing I do very good is to treat myself very well. Specially on learning an algorithm. I am like a super talent algorithm teacher, I teach myself first. What I do is to reach out top-talent people in Sillicon valley and also pacific area, and then figure out how they learn the algorithm in 30 minutes mock interview.

    One algorithm I ask over 14 time is called Leetcode 54: Spiral matrix.

    Code review


    Here is the Java code I reviewed on February 1, 2018 mock interview. It is such a beautiful solution, using direction array and also use extra space to mark visited.


    AngelList - Where the world meets startups

    March 24, 2018

    Introduction


    It is my favorite thing to do this Saturday morning. I had a mock interview, I spent less than 10 minutes to finish my algorithm, and the peer also finished his algorithm in less than 25 minutes. So we had over 20 minutes to chat about the jobs, careers, and things interesting to look into.

    One thing the peer shared with me is to look up the website called AngelList where the world meets startups.


    Startup 


    I like to learn how technology advances, but most of time those startup companies help our society move forward with technology and good service to enrich our life. 

    I used to work on a startup company back from 2000 to 2001. Some of my Chinese coworkers really grew from the startup company Trendium and later built up strong career after three to five years working for the company. 

    Startup is exciting and also very challenging. 



    Being interviewer: Leetcode 54: Spiral matrix

    March 24, 2018

    Introduction


    I had over 14 interview experience to ask interviewee to work on Leetcode 54: Spiral matrix. I like to go over each practice and then review the code. I am too busy to try new algorithms, it is still very good to review my past experience and figure out something to learn.

    Code review


    Here is my Feb. 6 interview code I reviewed. The interviewee is an excellent programmer and also pass one of top 4 companies onsite interview. He showed me how good he is a developer. He was very busy writing code, run test, and keep good presentation. Overall the presentation is so nice.

    I never experience such great presentation. I like to learn from his presentation skills. Overall the presentation of his code is perfect. I asked him to test one row and one column, and then he added a few lines of code before the while loop from line 48 to 52.




    Being an interviewer: Leetcode 273: Integer to English words

    March 24, 2018

    Introduction


    I have to say that I am a good JavaScript learner. I spent over 6 month full-time at work to learn JavaScript and then rewrote the JavaScript code for my current job back in 2015. One drill I like to do is to follow the peer when I interview on mock interview platform. On March 22, 2018, I had chance to watch how the peer worked on the algorithm using JavaScript.

    It is also good learning experience of JavaScript by observing, and asking questions.

    Code review


    Here is JavaScript code to pass all kinds of test cases.

    A few JavaScript features I like to look into:

    Keywords:
    Eval, const, $, ``,

    I like to give the test case for the peer to work on,
    let testNum = 1234567890



    Friday, March 23, 2018

    Leetcode 230: Kth Smallest Element in a BST (Julia 2nd practice)

    March 23, 2018

    Introduction


    It is time for me to work on the algorithm called Kth smallest elment in a BST. I like to write 10 ideas based on the discussion of Leetcode 230.

    2nd practice



    Leetcode 230: Kth Smallest Element in a BST (Julia 1st practice)

    March 23, 2018

    Introduction


    It is time for me to work on the algorithm called Kth smallest elment in a BST. I like to write 10 ideas based on the discussion of Leetcode 230.

    1st practice


    I like to write code based on this discussion by yavinci.

    Kumon maths

    March 23, 2018

    Introduction


    It is time for me to write a small topic related to Kumon maths. I learned Kumon from my college classmate this week, she showed me how she works hard to solve problems to help her child. Her child got gold medal for math competition in middle school.

    Kumon maths


    I like to do some research on Kumon maths. Here is one of my favorite articles.


    Being an interviewer: Find the 2nd largest element in a binary search tree

    March 23, 2018

    Introduction


    It takes some time for me to learn to be a good interviewer. I start to work on the improvement once I get some ideas how to perform a good interview.

    I had a mock interview on March 20 and then I could not understand the code the peer wrote, after 5 minutes discussion, I understood the algorithm. It is so interesting to learn that the peer thinks differently from my understanding of the algorithm.


    Code review


    Here is Java code I like to review.


    Find the 2nd largest element in a binary search tree

    March 23, 2018

    Introduction


    It is my routine to create a gist for the algorithm first. I read the blog about this algorithm called "Find the 2nd largest element in a binary search tree" first on interviewcake.com, and then go over the blog word by word, and try to put together the content in my own words and style.

    Here is the gist.


    HackerRank NCR code sprint: Spiral Message

    March 23, 2018

    Introduction


    I spent more than 30 minutes to review my own question on stackexchange.com, and I like to post an answer after 15 months. Here is the question I asked in January 2017.

    Code review


    I wrote the code again, here is the C# code. I will write an answer in short future.

    1. change variable names to make it more meaningful.
     startX is changed to rowStart,
     startY is changed to colStart,
     endX   is changed to rowEnd,
     endY   is changed to colEnd.

    2. Remove code related to check base cases like one node, one row, one column, set direction variables.

    3. Add base case one node and one column break statement just after the first leftmost column.
    4. Add base case one row break statement just after the second top row.


    My last 3 month practice


    The matrix spiral print is my most favorite algorithm, first in January I was interviewed and got low performance 1/ 4 problem solving rating. After that I tried to practice more than 10 ideas using Leetcode 54 discussion panel, I asked the question on stackexchange.com, and then i used the algorithm to interview more than 13 interviewees on mock interview platform. If I do learn something, I must learn from this algorithm.

    Here are the links to look up. I still get organized by adding/ modifying the labels on blog platform.

    Search by keyword: spiral matrix print, here is the link. Search using keyword: Leetcode 54: Spiral matrix, link is here.


    Leetcode 273: Integer to English Words

    March 23, 2018

    Introduction


    I had a mock interview to work on the algorithm called Integer to English words. Since I had a mock interview on March 21, 2018, I visited my friend and did not have a 22 inches monitor to work on. It took me around 40 minutes to work on the algorithm.

    It is challenging for me to read small font in the shared editor using my laptop monitor. I get used to read large font and can go over the code quickly using 22 inches monitor.

    Being a good interviewer


    I also like to advise my peer to learn to be a good interviewer. The interviewer should lead the interviewee to the optimal solution. I did tell the interviewer that I like to work on the solution based on the test case: 1, 234, 567, 890.

    Here is my practice in mock interview.

    Monday, March 19, 2018

    Leetcode 451: Sort Characters By Frequencies

    March 19, 2018

    Introduction


    I have worked on the algorithm including Leetcode 451 as a subproblem so many times called word count practice.

    I am so excited to find at least 10 ideas to solve the algorithm. The practice of the algorithm is to train myself using a few algorithms as small as possible, but I like to exhaust all options of the algorithm, get excited to know various approaches, pro and cons. Therefore, I can apply some ideas to the algorithm I have not met before.


    Algorithm practice is coming




    Thursday, March 15, 2018

    Build a new drill for daily workout

    March 15, 2018


    Introduction


    It is easy to stay in the comfortable zone. Specially when I work on the algorithm Knight's tour today, I feel so uncomfortable, I have to deal with an unknown problem, draw a graph, think about problem space, counting sort, seek tips, one after the another. Even though I know that I have to simplify the problem to make it straightforward one. It is called uncomfortable feeling.

    In order to push myself out of comfortable zone, I have to develop a drill for myself, work on a new algorithm every few hours in the day time.

    How to develop the drill?


    I chatted one of computer science graduate student, he just got Google intern offer. He told me that he has worked on Leetcode over 400 algorithms. What I have worked on, less than 150 algorithm from Leetcode.

    It is so easy to work on one algorithm. If I take a break every hour, I may just take five minutes break. Read the problem statement of the algorithm using 5 minutes. That is it.

    Whenever I have time, I will let myself think about the algorithm.


    Need more curiosity?


    I need to do some short research how to develop more curiosity on algorithm and data structure. Please list three ideas here.



    Knight's tour

    March 15, 2018

    Introduction


    It is very classical dynamic programming called Knight's tour. The problem statement is here on stackoverflow.com.

    The most important thing is to know that we only need to count the number of phone numbers, but we do not need to know what numbers for each phone number. The second tip is to know that there are 10 numbers for each step at most.


    Algorithm practice


    Here is my C# algorithm.

    My problem is that it takes me too long to come out the idea and write a solution. I need to make it fit into 20 minutes, 6 to 8 minutes to come out the idea, and I should be able to write the algorithm in less than 10 minutes.


    Thinking process


    We all know that most important is thinking process. Of course I had long thinking process this time. I drew something on paper, and I took time to think and play with the example.

    What I like to do it to make some presentable notes here and document my thinking process. Good thinking process is the gold, the coding part is easy specially for dynamic programming algorithm.

    1   2    3

    4   5    6

    7   8    9

        0

    We can tell that 1 can reach 6 and 8. Please check next row and then next column. we denote that knights[1] = new int[]{6, 8}.
    Same applies to each number in the first row, next row.

    One thing I have to pay attention is number 6, there are 3 numbers to reach, row above, row below, column before, knights[6] = new int[]{0, 1, 7}.

    Let us call it first play.

    Next play is to work on a graph using those numbers as node, and then connections as edges. It is directed graph as well. Originally in my practice, my drawing is kind of messy. In the following, I try to simplify and make the drawing more readable.

    For example, knights[1] = new int[]{6, 8}, I will draw like the following:


    0   1    2    3    4   5     6    7    8    9

         ----------------------->

        ------------------------------->


    And then we need to add knights[0] = new int[] { 4, 6},

    0   1    2     3      4     5    6    7    8    9

    ------------------->

    ------------------------------>

    We can use depth first search, but time complexity is too high using depth first search. We do not care the path detail. There are so many paths, all we care about the total number of paths.

    Once I decide to use a table to store all intermediate result. I have ideas to solve the problem using polynomial time.

    Suppose that we start from number 1, and then go over 4 steps and see how many results we can generate.


    3              1       3    4     2
    2    2   1       1            1
    1    0   0   0  0  0 0  1 0  1   0
    0    0   1   0  0  0 0  0 0  0   0
    -------------------------------------------------
         0   1   2  3  4 5  6  7  8   9

    Quora: How do I have a successful road trip 15 days cross the united states?

    March 15, 2018

    Introduction


    It is time for me to celebrate 8 years to land Canada as an immigrant. I like to write a quora article on the topic about 15 days road trip from Florida to the city of  Vancouver.


    How to get better on project management?

    March 15, 2018

    Introduction


    I like to try to write something more advanced, like project management. I like to see if I can start to build up some skills to do better project management.

    Let us talk about some failures first


    I will be back to work on here.


    Website project

    March 15, 2018


    Introduction


    It is the five years since I started to write my current company website. Recently I reviewed what I did starting from 2012 and then worked with a few web designers to design and code a website.

    I like to write a blog and share my experience how to develop a website first, and then seek ideas to improve the website.






    10 good things about mock interview

    March 15, 2018

    Introduction


    I like to write 10 good things about mock interview. I notice that I start to make a lot of changes, I care about the time spent on tennis court, and care about how many things I should purchase. No more cloth shopping, no more phone chat with friends. I am making new connection every day. I am more confident to meet hard working programmers.

    It is my short research how the daily mock interview can build up a mediocre software programmer to the top of world, good thinker in algorithm and data structure. It is 12:09 am Thursday morning, I have to prepare to sleep.

    It is not my day dream. I also can tell that I do make some improvement and get constant good feedback from my performance on mock interview. I feel so comfortable to do code review in my day time job. I could not believe that I like to rewrite so many things on the website and windows form apps. I even start to like to document my project management activities.

    10 good things 


    Let me think about more and how to find something subtle in my life, what are those 10 good things?

    No. 1:
    I do learn one algorithm very well. That is called Sudoku Solver. I have practiced over and over again last 12 months.

    No. 2:
    I start to learn dynamic programming, and I find that there is a lot of fun.

    No. 3:
    I start to code every day.

    No. 4:
    I start to give up some bad habit.

    No. 5:

    Wednesday, March 14, 2018

    The time to make change

    March 14, 2018

    Introduction


    It is so easy to tell that what is my weakness, I need to make change. I have to learn how to plan, analyze what my weakness in order to make some improvement.

    Time to make change 


    I like to write down three weakness today, and each one I will share a story and hopefully the weakness just reminds me that I am a healthy human being, just need to work on a few basics.

    I like to get organized on my github, I have more than one thousand gist with C# practice code. It is very hard for me to browse through those source code now.


    A google engineer

    March 14, 2018

    Introduction


    I still remembered that I met an engineer twice on mock interview last December, and then he joined Google.

    In other words, I should write a story like this, a future Google engineer coached me two hours how to be an excellent engineer.


    Something to remember


    I have to review the advice from the peer and then work on one of ideas.



    A linkedin intern

    March 14, 2018

    Introduction


    It is hard for me to build connection to outside the world. The first five years from 2010 to 2015 I worked in the city of Vancouver, I rarely had discussion with other software programmers. Starting from January 2015, I started to write coding blog, and then starting from March 2017 I practice mock interview almost daily. I start a new life style to get connected to the world.

    What is happening after I practice mock interview? I know so many things and also add more wechat friends from peers I met on mock interviews. More than one month ago, one of my wechat friends met on mock interview shared his linkedin intern offer.


    What I can do 


    I can celebrate and dedicate one blog to celebrate his hard work. I still remembered that I met him on Christmas day and he showed me how to solve Leetcode 10 using dynamic programming method.


    A google intern

    March 14, 2018

    Introduction


    It is good news from one of my wechat friends. Last 4 months I made a few Chinese friends through mock interview and we used wechat to talk since mock interview platform did not work to transfer audio signals.

    Yesterday I saw the news about the new Google intern. Such a good news.

    What I do 


    I have to ask advice how to learn algorithm and data structure from young master graduate student in university of Alberta. I still remembered that he did so well on Array quadruplet using python, he used the idea of two pointer techniques.

    We had discussion after mock interview more than half an hour.


    Leetcode 120: Triangle

    March 14, 2018


    Introduction


    I find my weakness on the algorithm problem solving. I need to practice a few ideas using Leetcode 120 Triangle to help myself to gain some strength.

    First practice 


    I chose one of discussion and studied the analysis and C++ code. Here is the gist. I spent a few hours to go over various ideas on the algorithm. I really was so surprised that I knew a few more great programmers in those discussion.



    One more practice of Leetcode 133: Clone graph

    March 14, 2018


    Introduction


    It is so sweet to read my last practice on Leetcode 133: clone graph. Here is the coding blog more than 2 years ago.

    Let me tell you a secret. When I read my own work two years ago, and then I try to follow what I wrote. It is just sweet feeling, I like the blog much more than the product I write at work. The software I build is to help me make a living, but code in my blog is mine.

    This sports teaching of Journal the practice really makes life change. It builds up so rich content for a person to grow as an engineer.

    I like to learn one algorithm a time. But it is so surprising to learn so many improvements in my C# code. I could not believe that I am a much better and happy C# programmer these days.

    Code practice


    Here is the C# code.


    Leetcode 133: Clone graph

    March 14, 2018

    Introduction


    It is the good practice to spend time on the discussion and then learn the algorithm.

    Discussion


    I chose one discussion and studied more than 20 minutes. Here is the gist with the analysis and Java code.


    Object-oriented design mock interview

    March 14, 2018

    Introduction


    It is the best gift from the peer in mock interview. I was asked a lot of questions in the mock interview, how to implement a user case? How to define an attacker? It was so exciting and I started to learn from the peer his hard working and his passion to write a game in a few hours.

    Also I shared my last 12 months experience, how I will approach the problem and what to look up.


    Mock interview 


    Here is the transcript for our discussion. The bible teaching is very good on this, do not walk alone, if you fall, the peer may help you to get up.


    Object-oriented design review

    March 14, 2018

    Introduction


    It is so exciting to have a partner to work together on the object-oriented design. The peer was very passion and like to apply factory pattern on the design. What an exciting project! Also the project is divided into two parts, version one and version two. We had half an hours discussion in mock interview, and later I received the code.

    Code review


    I work hard and also like to give some good support to encourage the peer to work hard. So I wrote a code review. Here is my review. I also pasted in the following:

    I read your email and also code. Overall I like to see the business rules are defined in your words, and user cases are defined in your function spec. But I am not sure if this practice is old school style. I may be wrong, sorry for my honesty feedback.

    You reminded me the elevator simulation algorithm I did last year in the contest. I ended up staying later 4:30 AM.


    So here is my coding blog called Hackerrank contest algorithm: elevator simulation.

    So here is the discussion panel.

    Here is the discussion panel about the algorithm. Every business rule is determined by players as a user case, so we have to define how many user cases in your design, otherwise you will fail test cases.

    I like to refer you to those discussion, one of test cases is wrong, then the publisher apologized for the error.

    I like to say that it is good idea to get involved in the community like hackerrank contest, some of problems are totally object-oriented design, you have to go through exactly the process of system design, define how to scale, storage, define user cases, and also data structure and algorithm design. There are unknown test cases to pass.

    Remember that I may have some hacker spirit, and behave like a warrior borrowed from tennis player Maria Sharapova; that is what I believe and just share with you. I do not worry about too much factory pattern or implementation. Sometimes you know that the job market is so competitive, you cannot expect that the project is waterfall style, you even do not have time to think about the pattern and you have to figure out the business rule you miss and hidden test case you can not pass, how to scale is more important these days, like I did in the contest, staying later up to 4:30 AM to try to score something to improve my ranking, just business-minded and stay aggressive.

    That is just my opinion, you can be very intelligent that you are believed that you can apply any pattern you want, if you have time, you have interest, and also you think that it is right thing to do.



    Learn the first time Leetcode 333: Largest BST subtree

    March 14, 2018

    Introduction


    It is the first time I learn the algorithm called Leetcode 333: Largest BST subtree. What I like to do is to quickly go over one coding blog about the algorithm, and then spend some time to go over the analysis. I chose the blog since the author wrote down his analysis and it is very helpful for me to understand the algorithm.

    I review the analysis in Chinese and then put them in a gist.

    Code review


    Here is the gist link.

    As a programmer, I think that it is more important for me to write down analysis for the algorithm. What I like to train myself is to be able to analyze the algorithm in great detail. Best thing to do is to find a coding blog and then go over word by word.



    Leetcode 333: Largest BST subtree

    March 14, 2018

    Introduction


    It is my favorite practice on recursive function again. The algorithm is not available as free one on leetcode.com, and it is called Largest binary search tree's subtree.

    Code practice


    What I did is to read some coding blogs, and also practiced once as an interviewer. And also I had chance to ask questions and the peer helped me understand the algorithm very well.

    Here is my C# practice. Since I do not have chance to run against all test cases, I may think about posting a code review on stackexchange.com. The time complexity is optimal one with O(n) where n is number of nodes in the tree.


    Actionable Items


    I studied one of coding blogs, and based on the author, there are two more algorithms with O(n2) time complexity. I plan to practice those ideas as well.


    Leetcode 365: Water and Jug problem

    March 14, 2018

    Introduction


    It is the most happiest time to learn a few algorithms in a few hours. It is not easy to find time to study a few discussion and then chose to write one of ideas, what I like to do is to put some test cases together and use the test case to help me figure out the algorithm design.

    Code practice


    Here is my C# practice.


    Sudoku solver

    March 14, 2018


    Introduction


    It is my most favorite algorithm in the world. I could not believe that I practiced today with an engineer in Oregon and also I did learn a few things through mock interview. I took extra 30 minutes to discuss with the peer about algorithm practice and exchange ideas. The peer recommended me to practice on codefights.com, consider the purchase of interviewcake.com algorithms with the answers.

    I remembered that in 2015 I did study over 5 solution on Sudoku solver algorithm, I spent over 40 hours to practice the algorithm. At that time, I thought that I was the expert on the algorithm. It was so naive and here is the blog link for those practices.

    Code practice


    I spent less than 10 minutes to analyze the algorithm, and then the peer asked me if I can improve the efficiency to get available numbers to replace '.' char. So I plan to use a hashset to store available numbers.

    After I finished the code, I ran the test cases, I only passed one of test cases. So I found out that the hashset should be digits from 1 to 9 excluding those number showing in the same row or column or 3 x 3 small matrix. I just naively got those numbers and put into the hashset instead.

    Here is the code. It took me exactly 30 minutes to pass all test cases. I spent around 5 minutes to fix all bugs.


    Codefight.com practice

    March 14, 2018

    Introduction


    I got some advice to practice on codefights.com. This is the second time I got advice to practice over there. I will check it out.


    Array quadruplet

    March 14, 2018

    Introduction


    It is learning experience to work as a mock interviewer on this algorithm similar to 4 sum. I had the great time to learn and gave some code review on the algorithm.

    Code review


    Here is C code with my code review from line 62 to line 72.