Sunday, December 17, 2017

Code review: Find kth largest element in the union of two sorted array (Follow up)

Dec. 17, 2017

Introduction


It is so challenge to work with the algorithm called Leetcode 4: the median of two sorted array. It is hard level algorithm. I have been worked on the algorithm more than two hours today.

First I wrote a bug-free code based on Leetcode 4 online judge. And then I wrote a code review to review my own code Find kth largest element in the union of two sorted array (Follow up) written more than 10 months ago.

Here is the code reivew I did in last 60 minutes.


Actionable Item


It is kind of fragile thing to perform algorithm practice. In order to write bug-free code, I documented every step and it shows that it takes over 10 months to learn one algorithm related to binary search, and actually it also takes a senior level Microsoft engineer to help me to find the bugs after mock interview.

The algorithm is so hard to write and we have issues without a lot of test cases from Leetcode online judge Leetcode 4.

Timeline of algorithm practice


11 months ago, I posted the algorithm question on code review, here is the link.

With the feedback of JS1's code review , 10 months ago,  I posted second algorithm to follow up. Here is the follow-up.

Today I practiced my mock interview over 100th times since this March 2017, I always meet the highest top players who works hard to prepare top level onsite interview like Facebook or Google in less than one month.

I have to share my practice and then work more than 2 hours to work on bug fixes, and coding style and all other engineering stuff. Be a writer first instead of just writing code.

Today I wrote a code review to fix my own mistakes over 10 months ago. Here is the code review link.

Leetcode 4: Median of two sorted array

Dec. 17, 2017


Introduction


I had a mock interview at 10:00 AM, and after the mock interview, the peer asked me how to solve algorithm in Leetcode 4.

After more than 20 binary search algorithm practices last 6 months, I just gave a talk how to solve the problem.

Algorithm


The problem statement:
To find the median of two sorted array.

Optimal solution is O(lg(n + m)), n and me is the length of two array.

My analysis


If two arrays are sorted, and then we try to find each median of sorted array first, and then see how we can relate the median to those two median values.

So we can not merge two sorted array, since it will take O(n + m) to merge two sorted array using two pointer techniques.

The idea is to simple, each sorted array we divide into two halves and then we have to decide to get rid of which half.

Code to share


The peer was really busy but the peer said that if you have the code, please send me an email. So I thought about the problem and remembered that I worked on the similar problem and asked code review before.

I was so proud of myself, so I sent the link. In less than half hour, the peer sent me email about test case failure.

Here are the report about complaint.

Input: [1, 3]
[2]
output: 1.00000
Expected: 2.00000

So I started almost 90 minutes to debug my code.


C# code review 


Here is the C# code to pass all test cases on Leetcode 4. 

And then, I wrote an email at 3:27 PM to the peer, here is the email I wrote:
Thank you to point out problems. Here is the code to pass all test case of Leetcode 4. 


 I modified the code based on your input. 

 First, line 10 I prefer to use meaning variable name, firstIndex, whereas line 12 lastIndex is used. 
 Line 30, 32, and 39, the function getKthLargest function is used. Remember that kth smallest number is matching your original input. 

 The rest are the bugs in my code, a few of bugs:

 1. line 52, add +1 to the formula nthSmallest, this is missing one bug. 
 2. line 74, it should be start2 + k - 1, missing start2
 3. line 79, should be start1 and start2, not 0, 0
 4. line 86, 87, missing start1 and start2
 5. line 97, missing start1
 6. line 113 missing start2

That is all. I am surprised that my code has 6 bugs. Without Leetcode test cases, I write buggy code. 

Sincerely, 


jianmin chen 

And the peer sent me an email saying that: Me too 😊

Actionable Item


Need to put some review on code review, fix the buggy code I wrote.




Leetcode 10: regular expression matching

Dec. 17, 2017

Introduction


It is the best mock interview so far I have. I met a very senior developer working in Seattle area, and then I have to work on the algorithm called regular expression matching.

It is the challenging algorithm and very classical. I was told to work on dynamic programming and the peer likes to help me to work on the analysis and coding. But my argument is if I write a recursive with memo correctly then it should be easily applied to dynamic programming.

Code review


Here is the code I wrote in mock interview. The peer gave me instant feedback right away, and also wrote comment right away while I write first few lines of code.

Line 44 - 53, the code failed 6 test cases, only passed two test cases. I was told by the peer that I missed the test case like "" match pattern string "a*b*.*".

Also line 51, if the pattern string has only one char, it should return checking (char == '.'). The peer explained to me by adding the comment, using test case to help me understand the bug.

I fixed the variable issue on line 61, patternIndex variable should be used instead of using textIndex.

It is time to say great thanks

Dec. 17, 2017

Introduction


I start to write a series of blogs related to "It takes village to raise a child". As a software programmer, I notice that I have developed so much confidence in writing clean code, readable code, self-documented code in 2017. People are so busy but they still find a little time to read my blogs. And then they are so busy but they like to share their experience with me through short phone conversation. It touches my heart every time I meet in person and talk through the phone. I feel that the world is so connected and I am making new friends. And also I start to understand the programmer job is actually people oriented, I have to reach out for help.

So it is my turn to write some thank you note to all the people working for various companies in 2017. Without those encouragement and feedback, I may be still the same quiet hard working lady, write coding blog every day, but now I am happy and healthy, make small progress every day, and  fully enjoy the beauty of coding.

My argument is this. Act like a super talent programmer, and then always find the joy to review the code, write a better one with more efficient, much better coding style, and also with advanced design of object-oriented. Now I spend less time to debug my code, and I always find myself to write a simple code.

Thank so many companies in 2017 to help me grow so well as a software programmer.

Amazon - January - Make my January so special and so challenging.

Google  -  February - Make me so excited, even though I experienced first car accident in my life in the same day, I learned to get more prepared for worse or for good thing in life.

Vision Critical - May -  Make me feel so special.

Copperleaf - I understand that how math can change the world, specially in financial industry

Refdash.com - I understand that every mistake I make in one hour mock interview, I also make  another great mark to show my progress.

Pramp.com - This is such a great company and I have chance to meet all over the world top talent people.

Amazon - July -  I worked so hard to push the limits to advance my coding skills.

Global Relay - September, Operating system question can be so challenging and great time to think about.

Microsoft - October - It makes me so excited to know how a start-up runs in the big company. So exciting to know the company and an engineering manager.

Amazon - October - I really like to think about work when I took vacation in China, I will try to compete again.

Stackoverflow - November - I always get the best advice and find my weakness in my skills.

Expert Roundup: Online Courses & Coding Bootcamps

Dec. 17, 2017

Plan to read the article first, and then look up more through google. Here is the article link.


Saturday, December 16, 2017

Learning to program: finding the best path that fits you

Dec. 16, 2017

Plan to read again the article: learning to program: finding the best path that fit you.


Css file does not get uploaded to browser

Dec. 16, 2017


Introduction


It is the administrator's work to make sure that the web browser will display latest Css file, I came cross the issue recently and I did some quick fix, add a version number after .css file.

I like to write a blog and carefully review the issue. Document the progress first, and see what I should do to keep working on the issue.

Follow up


Dec. 15, 2017

Set 1 minute expiration on the webpage
https://blogs.msdn.microsoft.com/rakkimk/2007/07/09/iis7-how-to-enable-content-expiration/

https://stackoverflow.com/questions/35969498/iis-8-0-add-both-expires-header-and-cache-control

How to get latest .css file?

https://stackoverflow.com/questions/15562384/how-to-force-chrome-browser-to-reload-css-file-while-debugging-in-visual-studio

Follow up


Dec. 18, 2017

Download Fiddle web debugger, and then try to figure out why the latest .css file is uploaded automatically.

Actually the .css file is not invoked by Fiddle log history at all.

Paysa 2017 top tech companies bonuses and employee retention

Dec. 16, 2017

Introduction


I read the article in Chinese on wechat, so I like to do 10 - 20 minutes study and also write a blog. I found the article in English, titled comparing top tech companies bonuses and employee retention. Here is the link.


Dynamic programming should be daily practice

Dec. 16, 2017

Introduction


It is hard to get used to write bug-free code for dynamic programming. Specially base case handling.

Here is C# code I practiced on Dec. 16, 2017 10:00 AM. The code I wrote had a bug to handle the array with length 1, the product should be 0 instead of 1.

Feelings


This practice I felt much better. First I read the problem statement loud, and then I spent over 5 minutes to go over the test case, and explained the brute force solution and its time complexity. And then go to optimal one, how to apply the two linear scan integrated with left neighbor or right neighbor products with one more multiplication.

First try to explain very clearly the idea, and then it is very easy to write the code just following the idea.

I have practiced this algorithm more than 4 times since March, 2017. I still made an error on edge case. I just added tags for all past practice using Leetcode 238: product of array except itself, so I can easy go over the past practices and review them.


Get organized


It is most important task to get organized, review every practice in one setting. So I can figure out how I develop good understanding of the problem through each mistake, and also get some ideas what to work on next.

Source code is the key information to document how good/ not good I am in terms of algorithm analysis, coding style, and also whiteboard testing.


March 21, 2016, here is the blog about the practice.

Oct. 29, 2017, here is the blog about the practice.

Dec. 16, 2017 practice is Here.

Thursday, December 14, 2017

Choose to be Maria or Matha

Dec. 14, 2017

Introduction


Bible story Mary Listens while Martha Labors (Luke 10:38-42) is my favorite, and I like to have wisdom to listen instead of worrying about so many things. And I want to write my mock interview experience and mainly reflect on my feedback. 

After both of us finished the turn to be interviewed, the peer told me that he tried to give me hint when I worked on the algorithm, but I did not give him chance to talk. It is not so good since I should pay attention to my peer. 

Also, I broke my promise to write optimal solution with time complexity O(logn) and space complexity O(1), but I just started to write at the very beginning to declare an array with space n, and copy the array to the new array using time complexity O(n). 

Am I a good listener? I learned the story of Mary instead of Martha more than 15 years ago when I was in Florida, United States. I will read the bible story, and try to relate the story to my mock interview feedback. 


Mock interview


It is another normal mock interview, my peer did not show up so mock platform matched me with one 10:05 PM. It is the algorithm I worked on before, the last practice is documented in the blog in Sept. 2017.

C# code is here. The code passes all test cases but time complexity is O(n) not O(logn), the space complexity is O(n) not O(1). I will make quickly change to remove diff array and integrate the checking with difference value arr[i] - i where arr is the integer array and i is the index.

After I performed the algorithm, the peer said that he never met any one like me before. He liked me to present the analysis first, and the way I wrote the code to solve edge case, find lowest index with value arr[i] = i is very efficient. The peer gave me hint how to make the minor change from line 34 to line 46, I just said that let us work on simple example, [0,0,0,0,0] is the array with five zeros, how to find the first zero index, which is 0?

I analyzed the test case first, and then I said that I do not want to scan the array from middle index to left, I need to do binary search as well. I explained the idea but the peer said that he could not understand it. So I wrote the code line 39, and explained that I need to make sure that left neighbor is existing and its value is 0 as well, so I will do another binary search.

Follow up after mock interview


I like to write the code based on mock interview code, and then remove the code to declare extra array from line 14 to line 17.

My last three practices on the algorithm are here:

1. June 8, 2017    (.ca)
2. Sept. 4, 2017   (.sh)
3. Sept. 14, 2017 (.mp)

All the above 3 practices have issues, need to do code review.

June 8, 2017 practice is here. Sept. 4 practice is documented here. And Sept. 14 practice is here.

The C# code written in Dec. 14 is reviewed after the mock interview, and the code is here to fix the bug, time complexity and space complexity is lowered to optimal ones.


Lesson learned 


This mock interview I practice to read loud the problem statement, not in rush, complete the reading and also let the peer hear. Because I read the problem statement loud and slow, I found that the smallest index has to be found and it is a challenging task to achieve the goal. I just cannot miss it since I read loud and slowly, and use gentle voice to calm myself down.

The reading part is also very important to practice in the interview, do not try to read silently, speak each word clearly like an actor/ actress to read the script in Suits. I plan to write a blog about watching the video script reading.


Feedback from the peer


The peer has great education and also very good work experience in Seattle area. The peer mocks for fun.



Quora study: Carlos Garcia Jurado Suarez

Dec. 14, 2017

Introduction


I read news feed on quora.com, and then I read the answer https://www.quora.com/Is-the-technical-interview-at-Facebook-easier-than-that-at-Google Jessie Su voted, I do not like the answer. So I read more on the question, I found one answer I like and also I find a lot to read. Big achievement for the day, Dec. 14, 2017.

The author of answer is called Carlos Garcia Jurado Suarez. I like to read those blogs related to career and continued education.

What a name, I know Spanish a little bitter more now.

Blog study


https://codepointers.com/

So sweet holiday message from Quora

Dec. 14, 2017

I got an email from quora about 2017 summary on Dec. 14 2017.

Here is the statistics I got from the email.

Will show some graph here. Good design and so happy to go over those numbers.


The design is very good. But I like to question a few things on the design or layout.

What is world's knowledge? Please clarify, a new term, I never hear the term before. It sounds like academic term, it should say that serious writer/ reader will like to write somethings to contribute the world.

I like a lot of users are not anonymous and share their knowledge, but my concern is that a lot of talk without any action. I try not to consume too many content from quora.com.




Code review: Calculate steps

Dec. 14, 2017

Introduction


I am comparing two versions of code, and tell what is the difference between two peers. One is current one who passes phone screen, and another one who failed second phone screen.

Here is the code.


Code review: convert to string

Dec. 14, 2017

Introduction


It is true that the peer I meet is developing new skills every day, soon or later, the peer will become very powerful programmer once the peer lands the first intern role.

Code review


The Java code written by peer has two issues, base case is missing 1 - 9, only 0 is considered in the base case. The recurrence formula is not designed properly. It should be rightmost digit stays after the recursive function's return.

Here is the code with my review.


Design challenge using object model

Dec. 14, 2017

Introduction


It is the learning experience to figure out how strong the peer is in terms of object-oriented design. So I asked the peer the question and I got some writing from the peer. I like to review the design later.


Problem statement


Let's say we're developing a vector graphics application. It will allow the user to create lines, rectangles, circles, text, etc. and manipulate them independently - move them, re-size them, etc. Design an object model for this application.

• How would you model the representation of the document in an object oriented language?
• What classes would you define?
• What methods would you have? What would your API look like?

Answer:

class shape{
    int x0, y0;
    int area;
    int[] getCoordinate(){
    }
    int getArea(){
    }
    void changeCoordinate(){
    }
    void changeArea(){
    }
}

class line extends shape implements Drawing{
}

class rec extends shape{
}

class cir extends shape{
}

class text extends shape{
    int x0, y0;
    int area;
    string content;
    String getContent(){
    }
    String changeContent(){
    }
}

class Pen(){
    Shape drawShape(){
}

class Drawing(){
Interface Drawing
{
}

Graph draw(Shape shape){
}


Julia's review


Think about S.O.L.I.D. principles, and also think about C# string class how many interfaces are implemented. Julia has to figure out how to do better by herself as well.

Follow up


Dec. 19, 2017
Plan to read those two blogs related to UML diagram.

1. Study UML graph, the article link is here, another link is here.

2. a blog related to UML graph, the link is here.

Proud to be a peer

Dec. 13, 2017

I practiced with the peer together on Nov. 4, Nov. 7 to help peer prepare for onsite interview in Nov. 2017, and on Dec. 13, 2017, the peer told me that he got the offer. I could not believe that I am becoming very good partner to prepare for important onsite interview. I like to review two algorithms we practiced together.


Leetcode 611 valid triangle number

Divide to n small linked list

Base case

Dec. 13, 2017

It is a long mock interview for me, I worked together with the peer second time, the first time was less than a week ago, the blog is here.

We worked from 10:00 PM to 12:40 AM. I asked two more questions to interview the peer.

The peer helped me to write an algorithm related to recursion, memoization, edit distance problem.

Code review

The C# code is here.


Follow up

After the mock interview, I realized that the memoization has issue. I should declare the memo jagged array with size new int[length1 + 1][length2 + 1] instead of int[length1][length2].

The memoization should record the value for the top row and top column.

Line 42 and line 47.

One thing I can do is to test the code using Leetcode online about memoization design issue. Another one is to read dynamic programming solution, and check the two dimension matrix and its size, base case handling.

The peer brought up a lot of good discussion about the code, I changed the structure of the code to remove redundant code from line 62 to line 73.

Object oriented design case study

Dec. 14, 2017

Introduction


It is time for me to review object-oriented programming, since I start to read C# string, array abstract class, I start to develop a lot of interest, and also I like the lecture note since it is so well prepared. I wrote my lecture note study recently in the blog.

Here is one answer I did back in 2013. I like to review and see if I can do better this time.

Wednesday, December 13, 2017

Convert to string not using itoa similar function

Dec. 13, 2017

Introduction


It is challenging to review the code I wrote back to Oct. 2013. I like to review the code as I did review code 8 years ago. My last blog was written in the blog titled: Algorithm: possible triangle.

Time line: Oct 2013


Here is the code I wrote in October 2013.

Time line: Dec 2017


Here is the code I wrote in Dec. 13, 2017 using recursive function.

Here is the code I wrote in Dec. 13, 2017 using iterative solution. Need to work on a simple version, I like to practice and learn some APIs, so I kept the version for my learning.


Code review 


I like to review the code written in 2013, the code is here.

Analysis of algorithm


First, the analysis of the algorithm is good in 2013's code, but it takes 10 minutes to write, it should take less than 5 minutes.

The whole paragraph should be organized better. And the comment should be written in the following based on my understanding of depth first search, I learn a lot from Hackerrank contest recursive function failures.

Depth first search


Use depth first search to do the work, recursive function can be designed in the following:
Do at least as possible, smart programmer learns math in computer science first. Being lazy is the status of master of math in computer science. Read more book called basic mathematics in computer science and figure out the depth first search, only thing I need to do is to figure out the base case.

What is base case? One digit number, just output new char[]{(char) (n + '0')}.

What is recurrence formula?
We handle the rightmost digit first, so the string can be concatenated as recursive + base case. If the integer is negative number, '-' should be the first char in the string.

How to get rightmost digit? use % operator, and then work on subproblem which is n/ 10.

Good things in the writing on Dec. 13, 2017. Algorithm is specified using depth first search, recursive function. And then the base case is clearly explained in the paragraph. And then recurrence formula is easy to work on.

Code execution


Let me go over line by line.

1. Line 20, int[] should be char[]. Return type is char[].
2. line 23, return char array, should be new char[]{'0'}, not "0".
3. line 28, do not change function argument. Declare a new variable.
4. line 25 - 30 should be written in the following:
var isNegative = n < 0;
var postiveOne = isNegative? -n : n;
two lines instead of six lines.
5. line 31, comment: "at least I have one edge case, continue later. need idea?"
Remove the comment!
6. line 37, for(;;), use while(true)
7. line 39, digitOne variable should be rightMost.
8. line 48, 49, move at the beginning, emphasis that it is the base case.
    if( loopInt < 10)
   {
   }

Overall, the code is not structured very well. The code should be self-documented. And the code is written as an iterative solution, but recursive function should be quick and easy solution to write. I was not a very good programmer back in 2013, I have to face the reality after the review of the code.

What happened after 2013?


Let us read the answer Julia wrote Top 10 reasons to write a coding blog on quora.com in 2017.


Action items


In order to punish myself do not focus on learning basic mathematics in computer science, I decide to spend at least 5 hours to learn vocabulary in the book, at least collect five hundred words. And those words will be posted here.

This is the drill I learned when I watch China Open tennis professional players did, after they tried to hit Mercede sign, the athletes have to do push up because she/ he fails.

Tuesday, December 12, 2017

Binary search practice

Dec. 12, 2017


Introduction


Binary search algorithm is getting easy to write and I wrote one more time on Dec. 11 10:00 PM mock interview. I wrote the algorithm using C# language and the code passes all test cases.

Code review


Here is C# code.

Line 50: return binarySearch(x, n start, end);

I forgot to write a recursive call as line 50 shows. After the whiteboard testing, I wrote the test case Root(7, 3) and then I found out the bug.


Follow up 

Dec. 19, 2017  10:14 PM

Binary search range should be discussed based on x value, if x > 1, then the search range is [0, x]. But if x < 1, then search range is [x, 1] instead.

The mock interview practice has a bug related to range to search.



Enumerable extension methods

Dec. 12, 2017


Introduction


It is a good idea to invest time to memorize Enumerable extension methods. I like to go over each API first, and then start to read LINQ and prepare myself for next project.

Here is the link.


Sunday, December 10, 2017

Binary search tree search from root to leaf node

Dec. 10, 2017

Introduction


It is the great learning experience for me to do mock interview tonight at 10:00 PM. I met an architecture tonight, the peer showed me how to write correct code first, and then reminded me to write optimal code as well. The search in binary search tree can turn left and then turn right and then turn left, but invariant is that the path is from root to leaf node, and the answer is always found until the leaf node is reached.

Code study


I practiced this algorithm so many times, last time I wrote a blog about the experience one month ago. Here is the blog.

Today I solved the problem with the help of the peer.

There are two bounds to work on. One is the lower bound value which is smaller than given value, and then the other one is upper bound which is smaller than given value. In order to find the upper bound, we are looking for the first value which is bigger than given value first, and then find a smaller value until one is found. Then we are sure that we are find the upper bound value.

In my previous practices, the upper bound value should be searched in two directions, go right to find bigger value, and then go left to find smaller value.

Feedback is encouraging


Follow up 


Dec. 13 ,2017

Finally I have time to come out a test case to illustrate the search, and the steps are left and right and left and right and left.

Here is the binary search tree, given value 7, the largest smaller BST key should be 6. How to find the node with value 6?

Start from root node with value 10, and then visit every node in the above tree, and visit the leaf node with value 6, and the answer is 6.

Code Review: Learn Trie from Leetcode 212

Dec. 10, 2017


Introduction


I posted a question on code review today, it is called Learn Trie from Leetcode 212. I got a comment to read patricia trie for space complexity, so I spent 30 minutes to read about it.


30 minutes reading


Here is one article I like to read, the link is Compressing Radix Tress Without Tears.


Mother Tesesa

Dec. 10, 2017


Introduction


Mother Teresa is the favorite character I know as a Christian. And I use her story to help myself to communicate with my sister back in China as well. Since we dispute on the immigration issue, do I make right choice to sponsor my nephew to immigrate to Canada? She insists that China is best place to develop a career and life, now it is not 20 or 30 years ago, young people choose to stay in China instead of immigration to United States or Canada. I think that Canada has best education system in the world, and also the young people have their own rights to make their own decisions.

I share my argument with my sister, life is not about money, how many income to have, how good the career you have. My role model is Mother Teresa, I do not want to compare myself to my sister or other classmates.

I always feel good to stay humble and make a living, struggling is good, learning is fun and life is also great without good wealth or health. My sister has never heard about Teresa before. So I also need to study more about mother Teresa, and hopefully I can be more educated and be confident to be myself.

Video talk 


Here is 19 minutes talk given by Mother Teresa, Acceptance Speech by Mother Teresa Media Player at Nobel prize org. I remembered that in Florida one time my friend in church shared me her story, talking about people can not afford a pair of shoes.

Saturday, December 9, 2017

Mock interview weekday 10:00 PM

Dec. 9, 2017

Introduction


It is the question a young graduate student asked me in mock interview recently, what is my motivation to practice mock interview? Am I preparing for interview or just for training and improving skills.

My story


I did write a blog on this topic before. It was more than four months ago. The link is here. The topic is to do your current job well. We have to learn how to serve the current employer very well. A lot of uncertain things will happen in the job, we have no control at all. But we can choose to do thing easy to be controllable, keep practice mock interview, keep meeting highly talented programmers, keep practice those thirty algorithms again and again on mock platform, learn one thing a time, practice one algorithm a time, learn from one peer at a time.

In order to get really good on one algorithm, I also ask the question on code review stack exchange to get more input from the general public.

Training is like favorite sports I like, tennis. I learn from professional tennis players, follow them on instagram every day. The top tennis professional players are very good to market themselves, educate the fans what is really a sports professional, I just learn how to do interval training from 詹詠然 Latisha Chan , problem solving skills. My favorite players are Alize Cornet, Elena Vesnina, 詹詠然 Latisha Chan.

We know that the algorithm and data structure plays so important role as a software programmer. We also know how the technology makes our life so enjoyable and so rich. We actually change the world through our daily work as software programmer. We have to train ourselves like professional tennis sports players do. To expedite daily problem solving, write highly self-documented code, and keep updated with latest trends in education, technology and hottest market - competitive career and job search, one of training I choose to do is to practice mock interview daily at 10:00 PM. Keep working on crafting skills, communication skills, whiteboard skills, the rest will come naturally.

New story


Through those hundred mock interviews, I learn to work on the same mock interview algorithm again and again. I actually train myself to learn various things, coding style, testing, and also new features in language, a new language, how to help and communicate, experience tough time, deal with tough situation. I document all the experience through coding blogs.

I used to write so complicated code, and worry about bugs. Every time I make code change I worry about all kinds of issues. One time I remembered that I may mess up existing code in the same function, for example, the function I have to work on is too complicated and it will take some time to rewrite and test them. Right now, I understand that it is more important to write with good coding style, good code principle instead of just making it work, I kill the code right away and start to write clean code. Zero tolerance on bad coding style, zero tolerance violation of coding principles like DRY, SRP, S.O.L.I.D., TED principle.


Education of computer science

Dec. 9, 2017

Introduction


It is normal 10:00 PM mock interview, but this is the first time I met a Chinese and also there was issue about audio through mock platform. I suggested to use skype phone number to get audio, instead the peer suggested to use Wechat to get audio. There are two algorithms involved, one is spiral matrix print for me, one is Sudoku solver for the peer. We talked about the algorithm and reviewed the code for one hour, and then we spent time to share the experience through wechat until 12:40 AM. It lasted 2 hours 40 minutes.

Backtracking bug


The peer wrote a Sudoku solve with a back tracking bug. I told the peer that Let me review the code and also help to find the bug.

I gave advice on coding style. Do not use i, j instead of using row and column.
Suggest to calculate the next row/ next column and express the intent to calculate.
Write first line of code in the function to discuss base case.
Remove if/ else and nested if/else, make the code flat, avoid smell of arrow-like code.
Most important is to discuss the backtracking and why it is so important to do it.

I enjoyed the discussion, I did see that people do not do backtracking and code still passes all test cases before. This time the backtracking has to be done, otherwise 5 out 7 test cases failed.

For example, Sudoku first row:
5 3 _ _ 7 _  _ _ _

For example, first _ can be filled with 9 possibility, from '1' to '9', for example, for example, '1' is tried, and then continue to second _ which is row 0 and column 3, '2' is put into trial. If '2' fails, then second _ with index of (0,3) should be backtracked to be filled '.'. We need to go back to the first _ to try next available number.

I showed the peer things to work on. Also I learned from the peer through his experience, he had 8 phone interviews for intern, 2 rounds of phone interview for interview, he definitely almost made it. Apple, Facebook, Uber and Microsoft.

All advice are from the code review on stackexchange.com, the question I posted over one month ago.

Talk of graduate study 


First document some facts about computer science graduate study and questions and answers:

1. It is hard to get in the computer science master degree program in Northwestern university. The tuition is expensive compared to Santa Clara university, $18,000/term vs $9,000/term.

2. To get a computer master degree, there are 45 credits in the program, non-thesis program. The tuition is around 45 thousand dollars, each credit costs $1,000 dollars. Private university, same tuition for international or noninternational.

3. Around 100 computer science master degree student, half are Chinese, half are Indian.

4. What is advantage of studying in Sillicon Valley?

5. How many of them get intern at Facebook or Apple? Compare to Waterloo university in Canada undergraduate program?

6. What is policy of work visa in USA? OPT or summer intern, 60 days limitation.

7. What is the like to work full time? Do you experience the tough algorithm similar to Leetcode algorithm?

8. What is difference between students with Leetcode practice and full-time programmers with same practice?

9. Rent fee in California, $800/ month for one room or $1100/month to share 2 bed/ two bath condo.

10. Teaching and learning in the university, what is difference? Santa Clara university vs Northwestern university.

11. What is my motivation to practice mock interview?



Suits TV show money talk

Dec. 9, 2017

It is time for me to look up the pay of Suits TV show. I read the article this morning. The article is here: Cast Of ‘Suits’: How Much Are They Worth?

Thursday, December 7, 2017

Binary search algorithm is very classical

Dec. 7, 2017

Introduction


It is learning process to practice mock interview. So many things are not under control. For example, today I attended 10:00 PM mock interview, time passed and I was matched with one after five minutes passed by. The peer said that the laptop has camera and audio issue, if I like to stop then I can do that. I offered my cellular phone number to make a phone call to get audio at least. And then the peer joined with audio on.

Binary search is such a challenging algorithm, I observed how the peer wrote code but somehow I did not take my opportunity to step in, gave the peer some hint to put the peer back in track.

Feedback 


Here is the evaluation I got. I need to work on communication.

I need to learn how to take mock interview seriously, no matter what happens at the beginning. Treat the peer like my customer. I have to show the peer how good I can solve binary search algorithm, it is give and take, win win solution. My best solution is here, I just got it after more than three practice. It does not matter the array is ascending order or not, I will get rid of half of array in my search each step. That is showing my attitude, head on to solve the problem.

Do not hold grudges. I still remembered that I waste hours to try to simplify the algorithm recently. Here is the blog about my last practice.

One bible verse to help 


It is good practice to review some bible verse before or after mock interview. Today I like to choose this bible verse help me to improve. Also I like to take chance to learn a few words. This bible verse is hard to remember word by word. I will give it a try next few days.

Ephesians 4:31-32 ESV / 694 helpful votes 

Let all bitterness and wrath and anger and clamor and slander be put away from you, along with all malice. Be kind to one another, tenderhearted, forgiving one another, as God in Christ forgave you.


anger
bitterness
clamor (?)
forgiving
kind
malice
slander (?)
tenderhearted
wrath (?)

Remember Chinese version first:

以弗所书 4:31-32Chinese Contemporary Bible (Simplified) (CCB)

31 要从你们当中除掉一切的苦毒、恼恨、怒气、争吵、毁谤和邪恶。 32 总要以恩慈、怜悯的心彼此相待,要互相饶恕,正如上帝在基督里饶恕了你们一样。

Binary search tree practice

Dec. 7, 2017

Introduction


Binary search tree definitely is my most favorite data structure this year 2017. I had written more than 20 times through mock interviews and also observe how peers perform on the tree a lot of times. I never learn a data structure with such rich experience, go through so many emotions. Every time I work on the binary search tree, I think that it is such a fun activity to do.

My practice


My C# code to write a binary search tree successor is here. It is the first time I had chance to write a test case to test my code in mock interview as well.

Life was so beautiful

Dec. 7, 2017

Introduction


I spent more than one hour to go over pictures I took with friends in Vancouver back to 2012, and then went back to 2008 in Orlando, 2010 in Texas Austin, life was so beautiful because I had some friends to go out together.

At top of mountain Bonnell in Austin, Texas, 16 days road trip from Florida to Vancouver, Canada. I visited so many national parks in United States. It was kind of so interesting to experience difference of landscapes of United States in such a short time.


Wednesday, December 6, 2017

Leetcode 393: UTF-8 Validation

Dec. 6, 2017


Introduction


The algorithm is to determine if the integer array has specified format with one to 4 byte data. I found out that best way to deal with nervousness is to read the problem statement again and again, more than four times. And then usually I understand the algorithm and bring back my confidence about bit manipulation problem solving. The problem statement is here.

Code review


It is time for me to review my practice of bit manipulation by looking up the blog using keyword: bit manipulation. The search result is here.

Review some basics from one of blogs.

Top coder - fun with bits, the article link is here.

Take some notes:
Use bits of an integer to represent a set. Not only does it produce an order-of-magnitude improvement in both speed and size, it can often simplify code at the same time.

Go over the most popular set manipulations in the following:

Set union         
A | B

Set intersection
A & B

Set subtraction
A & ~B

Set negation
ALL_BITS ^ A

Set bit
A |= 1 << bit

Clear bit
A &= ~(1 << bit)

Test bit
(A & 1 << bit) != 0

Extracting every last bit

Counting out the bits


It is time for Julia to learn bit manipulation again. What Julia likes to do is to read the article word by word and then spend 10 - 20 minutes to go over the terms and warm up the idea how to solve the problem to use integer to represent a set.

It is not so often Julia uses this technique at work, but it is easy to review again and get the idea.

Follow up 


Dec.16, 2017

I asked my mock interview partner to work on this algorithm together, and then we had some discussion. Here are the notes.

The input from the peer:

32 - Each integer has 32 bits

%256 - how to extract rightmost 8 bits?
/256   - move to next 8 bits
>>=8 - or right shift  8 bits

int = int[4] - one integer uses 4 integer

0****** < 128   - check the range
110**** >= 11000000 < 111000000
1110**** >= 11100000 < 11110000
11110*** >- 11110000 < 11111000
10****** >= 10000000 < 11000000

Julia's input:

- integer - bit mask
 set 8 bit - use an integer to represent a set, each integer 8 bits express different numbers

Set bit
A |= 1 << bit

Clear bit
A &= ~(1 << bit)

Test bit
(A & 1 << bit) != 0

Extracting every last bit

Counting out the bits

Apply the bit technique to current case:

test case 1 : (arr[i] & 1 << 7) == 0 - 0xxxxxxx  - figure out the leftmost bit is 0.

test case 2:   arr[i] >> 5 ^ 6  = 0,   judge  110xxxxx 10xxxxxx, there are four operations:
                  AND, OR, negative, XOR ->
The peer came out the idea to shift the first 8 bits to left 5 bits, and then XOR 110, it should be 0.

Reference:

Top coder article about bit manipulation. The link is here.

Editorial notes:


I worked with a peer with strong math and engineering background, the peer works hard; if I share some tips, the peer will come out the solution in less than 5 minutes.

Tuesday, December 5, 2017

Leetcode 37: Sudoku Solver

Dec. 5, 2017

Introduction


It is the classical depth first algorithm called Sudoku solver. I had great time to practice mock interview and completed the code and passed all test cases in 28 minutes. The peer was very helpful, and I was told that there is a bug on line 29 and missing a function argument on line 58 after I did whiteboard testing.

Here is C# code.


Dec. 6, 2017

Two more comments after mock interview, one is to understand C# keyword const and static, and second one is to think carefully about const variable meaningful name.

Static vs Const


I wrote line 5 public static const int SIZE = 8; in mock interview, compile error, so I quickly removed const keyword in the mock interview. Need to look into the const in C# again.

Later I learned that const is static automatically, but static can be modified, not readonly. So I should write line 5 like the following:

public static readonly int SIZE = 8; 

or

public const int SIZE = 8; 


SIZE or LASTCOLUMN


It is good to name a variable using meaningful one. Let us discuss more here.

Board is 9 * 9 matrix, I added = sign after < on line 9 to make line 9 in the following:
board.GetLength(0) <= SIZE

better saying
board.GetLength(0) <= LASTCOLUMN


When I did whiteboard testing, I added equal = sign.The matrix's SIZE is 9, and LASTCOLUMN = 8. So the variable name on line 5 should
better be called LASTCOLUMN = 8

Line 5: public static int LASTCOLUMN = 8.

Actionable Items


1. Read C# Keywords/Modifiers/Access Modifiers/const, the link is here. There are around 12 access modifiers, plan to read one by one. Abstract, async, const, event, extern, in, out, override, readonly, sealed, static, unsafe, virtual, volatile.

2. C# static vs const on stackoverflow, link is here.

Plan to read 10 minutes on this discussion:

Argument or facts:


It is interesting to note that const members are always static, whereas a readonly member can be either static or not, just like a regular field.

3. One more thing is to review code review website the algorithm I asked about Sudoku solver, and understand the code review about complaints about const value 8 or 9 all over the code. 

The code review is called Sudoku solver recursive solution with clear structure, I posted it 30 days ago. 

Yesterday once more Julia version

Dec. 5, 2017

Introduction


It is the learning experience to be a daughter back to 2014, my mom started her journey to welcome her dementia, she started to experience dementia symptom very early stage in daily life, prepared to live as a dementia senior with full time care, five daughters one son will help her to overcome the difficult time. One of my sisters was full time physician and took care my mom as a doctor does.


Related to learning experience, I had to watch my mom to memorize all her five daughters and one son's name, she said each of us name correct, and ask me if she did ok in 2014 Chinese spring festival while I was on vacation in the city of Yichun. My doctor sister gave her prescription to calm her down, otherwise she talked whole night face to ceiling lying on bed, talk all poems and songs she memorized in her 20s, 30s, I never heard before, it is correct and nice poem to document herself as very nice young person. And then she watched the TV, and told me that the character is her nephew. I recorded the video and I may post on youtube.com one day to educate how tough the dementia is as a disease.

I went back to China to celebrate Chinese new year in 2014 with my mom and my sisters and brothers and families, I planned very well for a road trip from Shanghai to Yichun, stopping by Wu Xi to visit lake of Tai, and teng wang tower in the city of Nanchang. Still remember that I learned something from the work, I bought same tennis shoes from size 6 to size 11, 5 pairs for my five siblings, and one pair for my nephew, I went to USA Bellingham sports store and got those shoes.

I like to dress red leather Jacket, so I had great pictures with my family. I had a road trip to cross the country over 1000 KM in less than 2 days. I visited the famous tower in the city of Nanchang.

Here are the pictures, all best memory are back when I revisit the pictures. My mom, my sister-in-law, my sister's granddaughter (my granddaughter).







Monday, December 4, 2017

My favorite verse: Proverbs 28:22

Dec. 4, 2017

Introduction


It is the drill I use to relax, kick out worries by memorizing a favorite bible verse. I have some thoughts about my finance future today, so I like to choose a bible verse about money.

Today I like to memorize the verse in English. Proverbs 28:22, The stingy are eager to get rich and are unaware that poverty awaits them.

箴言28章22节说:“人有恶眼想要急速发财,却不知穷乏必临到他身。”

What I do is to read the verse loud at least three times, repeat the word by word, and try to memorize. 


Julia's Handwriting


More Effective LINQ

Dec. 4, 2017

Introduction


Plan to look into 4 hours course called More Effective LINQ on pluralsight.com.

Now it is 10:27 PM, next 20 minutes I will learn the basics of the course, Discovering the Power of LINQ.


Code review: Leetcode 56: Merge Intervals

Dec. 4, 2017


Plan to review code review: Leetcode 56: Merge Intervals. I like to write C# code based on every review I got. 


Review 1: here is the link. 

Review 2: here is the link. 




Code review: LINQ and string.Split do it yourself practice

Dec. 4, 2017

Introduction


It is my favorite algorithm called LINQ and string.Split do it yourself practice. I asked the question over 8 months ago. On Dec. 3, 2017, I had chance to write similar algorithm using C#, and I like to practice the algorithm and write the code after the mock interview. 

Case Study: What if IIS runs out disk space

Dec. 4, 2017

Introduction


I like to write a blog about the case study: What if IIS runs out disk space? It is a good topic for me to learn how system is designed as an internet information server.

Plan to learn and write down what I have learned through my study.

Case Study 


How to prepare for IIS diskspace error?

Service unavabile -
WWW service stop, virtual disk space service stopped working, logical disk space stopping working

2 weeks before the day to show service unaviable, every day the error showed up about unable to write log file.

Event system view:


Event ID: 1011, 1002, 15002, 7036, 4

Sunday, December 3, 2017

Codefight recommendation

Dec, 3, 2017

Introduction


It is so good to meet a peer who likes to share her experience with career conversion plan, went through outco.io bootcamp and also coding camp.

Here are some recommendation I got from my peer today through mock interview.

https://codefights.com/

https://interviewing.io/

https://www.freecodecamp.org

girldevelopit.org

Learning is so much fun with people sharing their own experience. Julia learned so many things through hours discussion.

Best learning experience is to help the peer to succeed

Dec. 3, 2017

Introduction


It is the traditional two pointers technique, sliding window, with tough situation to handle left pointer to shorten the substring.

Two programmers were working together this Sunday morning 10:00 AM. The algorithm was written with discussion of the algorithm first with two test cases. And the code was examined carefully by the peer using whiteboard testing, and also platform Run test cases gave failed test case information.

Java code to study 


Here is Java code to study.

I almost forgot to write what I did to help the peer, I asked one question before the peer liked to write code. A test case ['a','b','c'], string is "aaefbcgaxy", and the minimum substring is "bcga".

Another thing Julia did is to look up Java HashMap get API, and reminded that if the key is not in HashMap, get API will return null pointer.



How to find smallest number?

Dec. 3, 2017

Introduction


It is 30 minutes and then I start to learn what I put into those 30 minutes to show what I can solve the algorithm. This is the smallest number to solve and it is kind of good one to demo the algorithm space and time analysis trade-off.


Code study 


Here is the C# code. I did whiteboard testing, and then I could not spot the bug missing a break statement, I added line 43. The code had a bug related to index-out-of-range error, so I add else if statement from line 26 to 29. The peer was very patient and gave me the test case to point it out.



a Suits US TV series fan

Dec. 3, 2017

Introduction


Suits is the most popular show I spent to watch each episode before. Here is the link. Plan to watch the video Meghan Markle & Patrick J. Adams on Suits. The video link is here. I like to learn how actors are working on their career and deal with low pay job very well, build up a success story at the end.

It is the normal Sunday morning, I went to bed around 3 AM, and got up around 8:30 AM. I need to open the window to get fresh air. So I wonder what I should do next. I cancelled 12:00 PM mock interview, just keep 10:00 AM mock interview. I like to go to Willingdon church. I spent 5 minutes on Netflix and then thought about pluralsight.com. But I decided to study 20 minutes interview for  actor and actress of Suits, Meghan Markle & Patrick J. Adams on Suits. The video link is here.

I plan to go to swimming before 5 PM. And I added one schedule of mock interview at 10:00 PM.


Saturday, December 2, 2017

code review: Find the smallest substring that contains some given subset of characters

Dec. 2, 2017

Introduction


The sliding window algorithm is very challenge one even after I posted Find the smallest substring that contains some given subset of characters  two months ago. Today 12 PM I had a mock interview and then I have to work on the similar algorithm with a peer from the United Kingdom. With the peer's help, I spent 50 minutes to go over the analysis and coding but still could not finish the algorithm writing, we had a chat about how to work on algorithm after we worked on both interviews 80 minutes. The peer asked a break, we took 20 minutes break to chat about algorithms. In last 5 minutes, I was asked by peer to finish the algorithm. I almost finished but timeout, time limit is 110 minutes. The fact is that I lost my writing on the platform.

I need to recall what I did about the coding, and then post the algorithm here. The peer had good advice for me to write the algorithm this time, the code will be different from the one I wrote before.

Coding


Now it is Dec. 3, 12:09 AM. This version of code passes 2 test cases, fail 5 test cases. The C# code is here.

There are two issues in the code, first the input ["A"], search string "B", the result should be empty, not "B". Second issue is "Index was outside the bound of the array".

Continue to work on the bug fixing.

Now it is 12:35 AM. I fixed all the bugs. The function's arguments are not meaningful, so I mixed them together, one is arr, one is str. There are more than four places I mixed them in C# code here, line 26, arr[index] should be str[index], same as line 45, line 47. I changed them to meaningful name using char[] source, string search.

Lesson learned


Lesson learned: Always use meaningful name. Express the intent. I should change the variable's name to avoid the errors at the very beginning.

The C# code is here to look up.
Line 58
var isNeeded = dictionary[visit] > 0;

Actually I wrote first like this:
var isNeeded = Array.IndexOf(arr, visit);

And the peer asked me the time complexity of Array.IndexOf, it is O(m) and m is the length of the arr length. I should make it O(1) time instead. The peer worked very hard to help me, he followed my analysis of algorithm, time complexity O(n) where n is the length of search string instead of O(mn).

And the bugs are fixed to make the changes on the following lines.

Line 65 - add dictionary.ContainsKey(current) to avoid run time exception. The peer told me to move line 77 - 85 inside the while loop starting from 58 to 88, to make the code more simple to write.

ToDictionary using LINQ


Julia wrote the code in mock interview, she is still learning how to write LINQ statement. She memorized the tip she got from the code review.

var dictionary = arr.ToDictionary<char, int>();

And the peer was confused, and asked what I was writing. So, I wrote a for statement instead right away. I did not know that I have to write two mapping for key and value using LINQ statement in mock interview.

The LINQ learning is challenging, I should write
var dictionary = arr.ToDictionary(c => c, c => 1);


Discussion between two peers


It is the first time Julia learned that how good a peer can perform on the recursive algorithm, specially how to compose the test case quickly with the art of simplicity, and followed with the code.

Julia also learned that a programmer from other side of earth, North Ireland. Julia thought that the peer must work for Nokia before, but it ended up that Finland is far away from North Ireland. The peer corrected Julia on this.

The peer praised that Julia did very well on analysis of the algorithm, best one in last 5 or 6 peers worked on the algorithm. Julia gave honest response. It is all about hard work. Here is the code review about the algorithm on stackexchange.com, Julia worked on the algorithm over 2 weeks in 2015, and then she practiced mock interview on the algorithm over and over again. Here is the blog about over 5 or 6 mock interviews on the algorithm wrote in April 9, 2017.

Julia later looked up the university of North Ireland, Queen's University Belfast and talked to her roommate about Great Britain, compared to University of Victoria.