Sunday, July 22, 2018

Leetcode 684: redundant connection - union find using array

July 22, 2018

Introduction


It is a medium level algorithm related to graph, and it can be solved using union find algorithm. The array can be used to store each node's parent node. I practiced a few times in the past, and this is the first time I wrote one and it passes the online judge.

My practice


Here is the C# code. I just copied the code from Java code in discussion panel. I may have issues when I write one by myself.


Hunger for more

July 22, 2018

Introduction


It is a 12 minutes video called BBC Wimbledon - Sue Barker and Chris Evert - 12 July 2018.

The first few minutes is about Serena Williams. The topic covers how she hungers for more, after having a husband and a child. The family helps her relax and she stops thinking about herself only. I really like to watch the video and understand the mental part analysis.

Here is the video.

Hunger for more 


Let me take some notes here.


Saturday, July 21, 2018

Comparison with a Google engineer

July 21, 2018

Introduction


I read Union find algorithm shared by a Google engineer after I finished my first practice on Leetcode algorithm: redundant connection. I am so surprised to read how hard a person can work on Leetcode algorithm.

Last year I submitted around 127 submission, but the person submitted 471 submission in the last year.

Hard work 


I cannot believe that people work so hard. I finally figure out that I need to focus on coding, and make things simple. The more I write Leetcode algorithm, the better I can be.

Here is the profile.

Here is the picture to show different number of submission. I can tell that Leetcode online judge is a very good tool to train myself to write code.


Leetcode 684: redundant connection

July 21, 2018

Introduction


It is a medium level algorithm called redundant connection. It can be solved using disjoint set data structure. I came cross the algorithm and was introduced through a mock interview more than six months ago. But I have not submitted any code on Leetcode online judge yet.

It is perfect time for me to write the code for the algorithm this Saturday.

My first practice 


Now it is 11:12 PM. I spent over 60 minutes and worked with online judge, and then wrote the code to pass all test cases.

I finally understood that the code is not easy to write using disjoint set data structure. I did a lot of learning through the those 60 minutes .

Here is C# code.


Second practice 


I read the discussion panel and one of ideas is to write union find algorithm, it takes less than 20 lines of code. I should be able to finish it in less than 20 minutes.


P!nk - Try

July 21, 2018

Introduction


It is most simple way to train myself by singing a song. I learn how to work on so many things, things troubling me. One thing is that I have a loose teeth, last time when I talked to my elder sister who is a physician more than 30 years in China over the phone, she asked me if I have a loose teeth. We only talked less than five minutes, how I can hide anything from an experienced physician.

But I love to sing songs when I feel frustrated working on algorithms. Today is my fun day since I do not work on any hard level algorithm, all those medium level or easy level algorithm are so pleasant to write.

Learn to sing a song


I like to catch up ways to sing a song by myself.

Here is the link of song.


What is the best way to learn the algorithm?

July 21, 2018

Introduction


It is very good research topic for my Saturday afternoon. I spent whole day to study inside my home office, I tried to push myself hard before I go out to play tennis and relax myself. What is the best way to learn the algorithm?

I did come cross the blog in April and like to review 98 algorithm videos prepared by facebook engineer called basketballwang. Here is the link.

I like to push myself to write as many as easy level algorithms this weekend. Here is report generated by Leetcode.com:

111/861/ solved, Easy 33, Medium 48, Hard 30


Preparation


I like to try to take an approach to work on easy level algorithms this time. I really like the easy level algorithm. I can quickly learn something and do not stress me out too often. The learning time is so much fun and I definitely enjoy the experience.

I also like to learn how to push myself to solve problems as well.


My experience


I do like the algorithm and data structure problem solving. I can tell the big difference through my performance. I do not know when I develop so much on the coding skills. People ask me a few times how long it takes you to develop the skills.

I certainly enjoy to write code for algorithms.

I do see my weakness. I have to build my skills through those Leetcode easy level algorithms. I like to the statistics showing that I have solved Easy 50 algorithms, and I have solved more than 120/ 861.

I created 10 blogs to prepare myself to watch 10 videos out of 95 algorithms prepare by a Facebook engineer this past April 2018. But I was too busy to watch any. Here is my blog link.


Learn to push myself hard


I will figure out ways to push myself hard. I am getting better on this way to train myself using Leetcode easy level algorithms. There are hundreds of easy level algorithm, and every time I submit online judge, I learn how to deal with the feedback and fix the problem right away.

Here is the code I wrote and submitted on Leetcode online judge this Saturday 7/21/2018 from 10:00 AM to 6:00 PM.



I wrote four algorithms, one dynamic programming called house robber, another one called unique paths II, and then I wrote one called Merge sorted array, and last one is called intersection of two arrays.

Here is my favorite icon to show how many problems I have solved up to 6:08 PM, 7/21/2018. I like to make training simple, solve 10 more easy level algorithm next.


Follow up 


July 26, 2018
Best way to learn the algorithm is to work on Leetcode easy level algorithm first. If I learn so many ways to solve easy level algorithms, it is so easy to use one of methods to solve a medium level or hard level algorithm.

If I can solve an easy level algorithm very well, it opens the door for a medium level or hard level algorithm.


Sept. 13, 2018

Leetcode 897 algorithms

Easy 265 / Medium 437 / Hard 195

May 9, 2019
Leetcode solved algorithms

Total: 1036

Easy 212 Medium 142 Hard 43

Leetcode 143: Reorder the list

July 21, 2018

Introduction


It is the medium level algorithm. I came out the idea how to solve the algorithm, find the second half, reverse second half as a linked list, and then merge two linked list. I checked the discussion and know that the idea to using three steps is correct.

I just wrote an easy level algorithm called Leetcode 234: Palindrome linked list, through the practice, I wrote the code to reverse a linked list. So I plan to write the algorithm in the future.




Leetcode 269: Alien Dictionary

July 21, 2018

Introduction


It is time for me to review the algorithm called Alien Dictionary. I do not know what I should do in order to get best benefit, I like to give it 30 minute study.

Alien dictionary


I like to learn something from my favorite blog called brandyang. I created a gist for his blog.

Also I found another better one in Chinese, so I created a gist for myself to study again. Here is the gist.



Leetcode 349: Intersection of two arrays

July 21, 2018

Introduction


It is an easy level algorithm. I came cross the algorithm, and I decided to write one solution for the algorithm. The extended algorithm is if the two arrays are sorted, one is much larger than the other one.

Here is my C# practice.

Will continue.

Leetcode 88: merge sorted arrays

July 21, 2018

Introduction


It is an easy level algorithm called merge sorted arrays. I spent less than 20 minutes to work on the solution. I like the way I handled the edge case. The code passes online judge.

Here is my C# code.

Extended algorithm


I am thinking about possible extended algorithm.


Leetcode 63: unique path II

July 21, 2018

Introduction


It is the dynamic programming algorithm called unique path II. I wrote the algorithm using C#. Here is my code.

Extended algorithm


I like to do some study how to extend the algorithm.


2018 summer with Facebook

July 21, 2018

Introduction


Facebook is such a great company and I like to work hard to learn something this summer. What I like to do is to use Facebook phone screen and onsite interview algorithm to train myself.

Algorithm and system design


I spent over 30 minutes to put together some algorithm questions from Facebook, and I like to work on those algorithms this weekend.

Here are a few links.

Link 1 is here.
Line 2 is here.
Link 3 is here.

Summer is such great time in the city of Vancouver. I miss those hiking trips.

Leetcode 198: House robber

July 21, 2018

Introduction


It is an easy level algorithm and dynamic programming can be applied to solve the algorithm. I think that it is so important to be humble. Once I decide to work on easy level algorithm last Tuesday, I start to notice that I have so many things to learn as a software programmer.

I do not need to stress myself too much. All I need is to train myself to solve problem using easy level algorithms first. After one week practice, I should have completed at least 30 easy level algorithms. So far, I have completed 10 easy level algorithms.

My practice 


Here is my C# code.


Mistake I made and index-out-of-range error, line 21 I should check array's length == 0. The index-out-of-range error is on line 31.

Talk is cheap, show me the code

July 21, 2018

Introduction


Talk is cheap, show me the code. This is a famous verse from Linus Torvalds. My ex-coach used to tell me that in one of coaching sessions. I like the verse but it is hard to practice on it.

It is my decision to cut down the mock interview and work on more coding on easy level algorithms. I notice that I should cut any mock interview to 45 minutes at most, so I have more time to write code.

In order to train myself in terms of algorithm and data structure, I think that good thinking is important, and I can learn from each individual and pick up soft skills through mock interview. But most of important is to train myself to understand the problem, write code in less than 20 minutes.

Stack practice


I have worked on my current job last eight years. But I have not solved algorithms using stack data structure over 20 times. I need more practice on stack data structure in order to be a better programmer. My last stack data structure practice took me more than 8 hours, I need to get more familiar with the data structure.

I learn from over hundred of mock interview, when I work with so many peers on binary tree, and learn so many ideas to work on binary tree. I continuously work on tree every day for a few months, it is becoming my daily life. I am so happy to work on binary tree related algorithm.


Be disciplined


It is so easy to get hooked on facebook messag app or wechat app. I still think that a good programmer should be able to communicate clearly.

I choose not to use those apps for chatting. I like to write more code. Also I like to be independent and do not need extra information through social chat.


Actionable Item


Be careful, do not waste time on inefficient mock interviews. I need to cut down the time to discussion and work on more coding, work independently.

Facts


45  minutes for an algorithm mock interview is enough. Usually two algorithms are allowed for 60 minutes.



Friday, July 20, 2018

Easy level algorithms

July 20, 2018

Introduction


There are so many easy level algorithms on Leetcode.com. I like to find out ways to get familiar with those algorithms this weekend.

It is much more fun to work on easy level algorithm compared to hard level algorithm. The problem statement is easy to read and there are so many good ideas out there.


Study notes


8:30 PM

189 - Rotate array - O(N) time O(1) space - reverse the array in place, reverse three times.
198 - House robber, dynamic programming idea is so helpful. The link is here.

10:20 PM

I have checked those algorithms and read some solutions:
206, 217, 219, 225, 226, 231, 232, 237, 242, 243, 246, 257, 258,

Leetcode 554 - brick wall algorithm

July 20, 2018

Introduction


It is time for me to write the algorithm again. My last practice is more than one year ago. I like to apply line sweep algorithm.


Leetcode 234. Palindrome Linked List

July 20, 2018

Introduction


It is an easy level algorithm. But I spent over 30 minutes to write the code using O(N) time and O(1) space, N is the length of linked list.


My practice


Here is my C# code.

Leetcode 231. Power of Two

July 20, 2018

Introduction


It is an easy level algorithm. I spent less than 20 minutes to write the code.

My practice


Here is my C# code.


Leetcode 203: Remove Linked List Elements

July 20, 2018

Introduction


It is an easy level algorithm related to linked list. I had good time to work on the algorithm.

My practice


Here is my C# code.


Leetcode 202: Happy Number

July 20, 2018

Introduction


It is easy level algorithm. I had good time to rewrite the algorithm in less than 30 minutes.

My practice 


Here is my C# code.


Leetcode 190. Reverse Bits

July 20, 2018

Introduction


It is an easy level algorithm related to bit manipulation. I just could not believe there are some good ideas to learn this time again.

My practice 


Here is my C# practice. I just could not how much fun I had to work on the algorithm again. I have not written bit manipulation long time. Nervous, frustration, and then confusion, and so happy to find one blog with so clear explanation. It is learning experience, I just could not believe that a software programmer needs to practice the bit manipulation algorithm very often.


Thursday, July 19, 2018

Cracking the facebook coding interview - the approach

July 19, 2018

Introduction


I searched google and then I came cross this slideshow. Here is the link. Here is the handout.

I like to write down a few lines of notes for the video talk prepared by Gayle.

Notes

Design question


Scope - scope the problem -> ask question, make appropriate assumptions
key components -> can be somewhat naive
Identify -> Issues -> bottlenecks, tradeoffs
Repair & Redesign

Discuss top -> down


Push yourself

34:51/ 1:47
When I ask you a question, my assumption is that you do not know how to solve it. You will be comfortable to seeing a problem, being hard, and finding techniques to make progress.

If you practice, the technique is to look up the back of the book. You will be out-of-luck in the interview. So really feel the comfortable to push yourself. (35:12)

It is not quantity game. It is about quality. Spend time to push yourself. It is hard, find techniques to make progress.


Resources

Here is the link of page on crackthecodinginterview.com resource page.





3 benefits to write easy level algorithms on Leetcode.com

July 19, 2018

Introduction


It is Thursday night, 10:06 PM. I like to spend 20 minutes to do a small research on working on Leetcode easy level algorithms.

I do not have a habit to write code every day. When my ex-coach told me this Tuesday that I should write 10 easy level algorithm a day, 10 to 15 minutes on one algorithm. Write 70 to 80 easy level algorithms first.

It is time for me to listen to my coach. He told me before June 6, 2018 when he coached me 10 session. I know that I am stubborn. It is not easy for me to accept the new idea, even though he was my coach. I did not practice and submit easy level algorithms.

30 minutes research


First of all, this is the idea from my ex-coach, write easy level algorithm every day. Why I need to write code every day, 10 to 15 minutes for one easy level algorithm?

I know that I have a bad habit first five years working on my current employer. Every time after the work, I stay at home, I may spend more than 30 minutes to read wenxuecity.com, or spend over one hour on wechat.com.

Here is the question on quora.com about "How do top programmer choose problems in online judges that improve their problem solving skills?". I plan to read as many answers from this ICPC world finalist who gave 119 answers.

I know that easy level algorithm is very good warmup, good for my brain and I can learn how to control my nerves very well through those algorithms. Online judge is a really good tool to challenge me to think hard and solve problems reported by online judge.

I will be very humble right away since I will have problems to solve easy level algorithms.

Last few days I solved two easy level algorithms. Both are my favorite ones.



Follow up 


July 30, 2018

It is time for me to understand how a person can perform 10 times better compared to myself. I can train myself using easy level algorithms.

I will see myself perform up and downs. Either within 5 minutes with eaze or struggling over 30 minutes, I will learn and improve and become a strong programmer in the long run.

It is time for me to focus on more on crafting skills, test cases, edge cases, and be able to read, think, learn the algorithm every day.

Wednesday, July 18, 2018

Leetcode 438. Find All Anagrams in a String

July 18, 2018

Introduction



It is easy level algorithm related to find anagrams in sliding window. The problem can be solved using counting sort and dynamic programming. It is so nice experience to write a C# solution using less than 20 minutes.


My practice



I quickly fixed the issue since online judge reported the errors.

Here are the highlights of issues found:

1. Line 42, need to add extra checking in the second condition: (pLength + i - 1) < sLength
2. Line 45, missing - 'a' to convert to integer
3. Make sure on Line45 string s access of index is in the range, so (pLength + i - 1) < sLength is added. Think about i = 1, end position is pLength - 1, and then think about start position from i and end position pLength + i - 1. (i, pLength + i - 1) covers pLength's chars.

Here is c# code:


Leetcode 125

Leetcode 301: remove invalid paretheses

July 18, 2018

Introduction


It is hard level algorithm and I have to review the algorithm first. Most of important is that I have to understand how to write working code, and then pass online judge. I reviewed one of submissions I did more than 6 months ago.

Most of important is to write a story how to solve the problem using test case "()())()". I found this test case through my last submission. I have to explain my solution based on this test case.

Story first, code follows


I have to write a story how to work on the test case, I have to write a story. And then I need to conduct time complexity as well.

I put the story in the function specification. I reviewed the code and made some changes.


Here is the code.


Explain how I will solve the problem using test case "()())()", and the valid strings are "()()()" and "(())()".

And based on the test case, explain the time complexity of the algorithm. For example, first part of string is "()())()", second part is same string, how many valid strings we have.



Follow up


July 20, 2018

In order to figure out time complexity, I like to work on the test case with string ()())() repeating twice like ()())()()())(). How many valid string can we generate?

Based on my last practice, the string ()())() is removed extra close parathese and there are two valid strings. One is ()()() and another one is (())().

For first valid string ()()(), concatenated by ()())(), how many valid strings can be generated?
()()()()())()
       
When I work on the extra close paratheses, there are five options to remove ). So there are five valid strings:

(()()()())()
()(()()())()
()()(()())()
()()()(())()
()()()()()()

so in total there are 10 valid strings.

We like to find the upper bound of number of valid strings. Each substring ()())() has two valid string, but the concatenation of two generates 10 valid strings, not just 2 * 2.

I used to be math major. I like to figure out the upper bound. I do like to get more experience on a concrete example. My understanding is that I may have barrier to think clearly about the problem since I do not have any good experience on one test case.

It is time for me to build a good test case and write down some learning here.


Try to explain 



There is new case to remove extra close paratheses. In the first string, two extra paratheses instead of one can be removed. We know that ()())() string at least one close parathese should be removed.

The extra user case explains there are extra 6 valid string available after concatenating two strings. There are three options to remove two close parentheses.

Leetcode 493: Reverse Pairs

July 19, 2018

Introduction


It is a hard level algorithm called reverse pairs. I like to write code for the algorithm.

Leetcode 387: First unique character in a string

July 18, 2018

Introduction


It is an easy level algorithm. But I could not believe so many mistakes I made in my code. I spent over 20 minutes to try to fix the bugs. It is not easy for me to write an easy level algorithm after a few months break.

Continuously writing three algorithms in a row is such a fantastic job to do. I have not experienced this long time.


My practice 


Here is my C# code.



Leetcode 273: Integer to English Words

July 18, 2018

Introduction


It is hard level algorithm. I had some discussion with a peer through mock interview more than three months ago. But I did not write code and did not submit anything through Leetcode online judge.

I know that it is important to write working code and pass online judge. And also I need to work hard to submit as many algorithms as  I can. The number cannot lie.

I have to submit code through Leetcode online judge, I like to demonstrate how hard I work on the practice. So I tried very hard to put together code today.

I like the effort I spent on the algorithm, although I still spent over 45 minutes to write code. I like to encourage myself to write more code in short future.

Every algorithm counts


It is best time for me to write a hard level algorithm when I have doubt for myself. I had good time to write code but there were so many mistakes in my code. I had to work on the bug fix depending on Leetcode online judge.

There are more than five places I stumbled this time since I had not written code a lot last few months.

Here is my C# code.

1. Line 19: Forty spell error: Fourty
2. Line 30, forgot to declare a variable called workingNumber,
3. Line 45, I did not reduce workingNumber to a smaller number first writing
4. Line 50, I tried to simplify the code, always a space is added
5. index out of range error, line 66, current is bigger than 1000 in my first running
6. current / 100 -> I wrote current % 100 at the first time, the bug was fixed
7. Line 77, biggerThan19 variable for the case is forgotten in my first writing


Life is so simple when I work hard to write code for a medium level algorithm. I just keep writing code and follow my coach's advice.

Time spent:

More than 30 minutes

My last practice is in the mock interview in March 2018. Here is the blog.

I just could not believe that I did not submit any code after March 2018 mock interview. It is important to get some training through Leetcode online judge.

Facts


As of July 18, 2018, solved 101/861, accepted submission: 759/511, Acceptance rate: 50.7% based on my Leetcode profile:
https://leetcode.com/jianminchen39/

Leetcode 113: Path sum II

July 18, 2018

Introduction


It is the medium level algorithm called path sum II. It is my favorite recursive algorithm and I still spent over 15 minutes to work on the code.

My practice


Here is my C# practice. This is my first time I submitted the algorithm on Leetcode.com.

Easy level algorithm as corner stone

July 18, 2018

Introduction


It is true that I only have submitted 100 algorithms on Leetcode.com. I have not fully used Leetcode online judge to train myself.

It is most profitable business to do next two weeks. Practice as many as easy level algorithms as possible.

Great advice 


I should try to write an easy level algorithm on Leetcode.com, 10 to 15 minutes each, try to write over 10 easy level algorithms as possible a day.

Advice from my favorite ex-coach who has submitted over 500 Leetcode algorithms this past Tuesday July 17, 2018. Those 35 minutes talk will bring me back to reality, stay grounded and reduce time to social chat, and mock interviews, and focus on coding.

Great thanks to those working hard with submission over 500 Leetcode algorithms. It shows the determination, hard working spirit.  I want to be one of them in short future. I need to set a target for 120 algorithms first, right now I have submitted 100 algorithm only.

Facts


As of July 19, 2018, solved 101/861, accepted submission: 759/511, Acceptance rate: 50.7% based on my Leetcode profile:
https://leetcode.com/jianminchen39/

Here is the graph to compare my ex-coach with me on Leetcode profile:




I like to call the coach mindset as a champion mindset. Prepare, prepare, get prepared early. 

Tuesday, July 17, 2018

100 hard level algorithm 2018 summer campaign

July 17, 2018

Introduction


I like to have a campaign to study 100 hard level algorithm this summer to celebrate my eighth year on the software programmer job. Every hard level algorithm teaches me a lesson. I really appreciate the time and people involved to help me gain the experience.

Here is the github folder to contain the hard level algorithms I will select and document my learning experience.

Quora answer


I asked the question first and then wrote an answer on quora.com. Here is the link.

Leetcode 527: word abbreviation

July 17, 2018

Introduction


It is hard level algorithm called word abbreviation. It is the first time I spent time to work on the algorithm. Here is the gist I created for my study.


Leetcode 517: Super washer machine

July 17, 2018

Introduction


It is the hard level algorithm called super washer machine. The idea to solve the problem is kind of interesting. I like to study more later.


Here is the gist I created to help me understand the algorithm and learn an idea how to solve it.


Leetcode 514: Freedom Trail

July 17, 2018

Introduction


Every hard level algorithm deserve me 30 minutes. The algorithm is called Freedom Trail.


30 minutes study


Here is the gist I studied around 30 minutes.


Leetcode algorithms

July 17, 2018

Introduction


I like to spend one hour to go over those Leetcode algorithms. Leetcode 113, 125, 269, 301, 273, 387, 493, 721.




Sunday, July 15, 2018

Tennis WTA coach wim fissette

July 15, 2018

Introduction


It is time for me to study one coach named wim Fissette to help Anger Kerber to win grand slam Wimbledon 2018.

It is something I like to learn from the best coach in the world. I can tell that the coach is so difficult job to do.

A lot of videos to watch


Here is two minutes video, very good one to watch more than once.


Being aggressive was the key

July 15, 2018


Introduction


It is time for me to watch 20 minutes video from Anger Kerber, wimbledon champion. Here is the video link.

Notes


2:00/ 20:00 - Do  not think about too much. What will happen.

2:40 - Come back, without 2017, I could not learn so many things about myself; Make my day schedules. Find motivation after 2016. Such a year is impossible. Try to be a better tennis player, a better person. Try to enjoy the tennis again.

3:52 - She pushed me to the limits. To play final with her, ... Today I had to take the match at my hands.

5:28 - Being aggressive, playing my game.

6:02 - new coach brought about to her. One of keys is to serve good in important moments.

6:49 - play final with Serena. Not thinking too much. Stay cool. Do not show emotions. Going for that. It is not so easy to say. You can do your best.

7:44 - I am 30 years old. So many experience over the years. It helps me to relax. Focus on the match. You have to go through all the things. You have to learn.

10:00 - three grand slam. Play final second time here.

15 minutes break - 7 Can challenges video

July 15, 2018

Introduction


It is time for me to work on reading the book Elements of programming interview. I am kind of needing tea or things to stay alert after more than one hour reading. I like to watch Can challenge video of WTA, 7 videos for my favorite 7 players.

Here is the video link.

First break


It started from 12:40 PM - 1:05 PM, 7/15/2018.

Leetcode 277: Find the celebrity

July 15, 2018

I plan to work on the algorithm at least 30 minutes. I like to get the idea how to solve the algorithm in most time efficient method.


Saturday, July 14, 2018

Two hours coach

July 14, 2018

Introduction


It is so enjoyable to be a coach today on tennis court. I met three young Chinese again in front of tennis wall. I decided to coach two teenagers to play tennis, and also coached a young 23 years old UBC graduate how to play tennis on tennis court.

I have played tennis over five hundred hours and also paid so many coaches for so many private lesson. It is so easy for me to coach the young girl how to adapt tennis footwork, how to walk and run, communicate with the peer etc. It was so much fun for me to be a coach, the workout two hours were so happy and enjoyable.

It is so much fun to work with the young generation. I also talked about my nephew a 24 years old, my sponsor application. Summer time is so much fun to hang out on tennis court.


My six minutes warmup video using medicine ball: Dua Lipa

July 14, 2018

Introduction

It is time for me to find some good video for me to warm up before I go out to play tennis. I found one and also I like to play the video a few times today.

Here is the video link called Opening UEFA Champions League Final.

Summer reading: Elements of programming interview

July 14, 2018

Introduction

It is time for me to start to read the book called Elements of programming interview. I am looking for ways to improve my reading skills.


Summer reading: C++ code is my favorite

July 14, 2018

Introduction


It is so exciting for me to start to go over 500 Leetcode algorithms written in C++. I like to spend next two weeks to read C++ code. What I like to do is to read the problem statement, and then think about five to ten minutes, and read C++ solution.

My summer time bible


I used to call this solution as my bible for next three weeks. I like to go over the solution one by one again. I know that the hard working person will make his code as clean as always.

It is so busy summer time. I like to get some good reading material. Learning C++ from Leetcode solution definitely is also a good style.

Here is Leetcode solution written in C++.


Facebook algorithms

July 14, 2018

Introduction


It is time for me to go over those 70 asked algorithms by Facebook. This time I marked the repository on github.com using star. I like to go over those algorithms again.

One thing I like to do is to go over the notes prepared by this facebook engineer, and see how good she is compared to me. What I can learn from her? The way she organized the document is much better and it is so easy for me to follow her.

One algorithm a time


Here is the link for those algorithms. I like to go over those algorithm this Saturday.


Find a path with minimum maximum value in the matrix

July 14, 2018

Introduction


It is the extended algorithm and binary search algorithm can be applied. The most important is to lower down the time complexity to be controllable. I took the major hint from the mock interviewer and then we had discussion of time complexity. I did learn a lot from this mock interview.

Algorithm discussion


Here is the discussion transcript.


Actionable items


The peer gave me a few advice. Read two books, one is cracking code interview. One is elements of programming interview. And also we discuss how efficient we can do to have mock interview together, how often we can meet. The peer is in Asian country, I am in Canada.

The second advice is to get Leetcode subscription by month, $30/ month. There are a lot of similar algorithms discussed in those paid subscription.

We had discussion about Leetcode algorithm practice. The peer completed around 500 algorithms. But I have around 100 algorithms so far only.

Another discussion is to give each other 10 Leetcode hard level algorithms you have worked on since last meeting. And ask the peer to work on the hard level algorithm one by one in 5 minutes, and then give hint to help if the peer cannot solve. The peer said that it will not work for him.


Lessons learned


When I search the solution, I have to try to find the optimal time complexity as soon as possible. Please have an open discussion with the peer as early as possible. 

What is the brute force solution and time complexity? Can we lower the upper bound of algorithm?

For the algorithm to find minimum maximum value in the path, we have to find the range of value of matrix first, and use it to measure the time complexity of the algorithm. 


Statistics


Meeting time July 14, 2018 9:00 AM PST - 11:10 AM PST

First the peer worked on the infix expression to binary expression tree, and then I worked on the two algorithms, discussion of "Find a path with minimum maximum value in the matrix".


Find a path with increasing value given two nodes in the matrix

July 14, 2018

Introduction


I was given an algorithm to work on called find a path with increasing value given two nodes in the matrix.

10 minutes discussion


Here is the transcript for the discussion. The peer asked me to write code. I told him that I chose not to write code, and go for the extended algorithm.


Clone graph

July 14, 2018

Introduction


I spent 10 minutes to discuss clone graph algorithm with the peer. It takes some time for the peer to understand the requirement. We had discussion, the gist is here.


Infix expression to a binary expression tree

July 14, 2018

Introduction


It is the second meeting with a peer after six months. We met together this January 2018. And then I gave him the algorithm to work on which is to construct binary expression tree using infix expression.

Problem solving


The peer is very strong at coding skills, so he chose the optimal solution linear time O(N), and tried very hard to figure out how to design parsing algorithm using stack.

Here is the transcript how he approached the problem. I can tell that he is very smart on time complexity compared to me.


My feedback


The peer did very good to find optimal solution, try to use stack to parse the string once and build a binary expression tree. The time complexity is O(N), N is length of infix expression. And the peer communicated very well, there are multiple solutions and he decided to push the number and operator to the stack and also build a binary tree node in the same time. Somehow he should think about validation of expression string, and also try to simplify the code. 

Here is my feedback gist.




Statistics


Meeting time July 14, 2018 9:00 AM PST - 11:10 AM PST

First the peer worked on the infix expression to binary expression tree, and then I worked on the two algorithms, discussion of "Find a path with minimum maximum value in the matrix".


Follow up 


July 16, 2018


I wrote C# code to implement the algorithm using O(N) time complexity, N is the expression length. 

Meetup at 7:30 AM

July 14, 2018

Introduction


I had a meetup with the peer this morning at 7:30 AM. I usually did not get up so early. But I did because the peer complained that it is not easy to get mock interview on interviewing.io. I agreed to work with him and work on a few algorithms.

Problem solving

I did not save his code. But I did spend one hour 30 minutes to give him two algorithms to work on. One is to construct binary expression tree using infix expression tree, and the second one is to clone graph.


Actionable Items


I need to learn how to work with people with various background. Sometimes I can tell that peer is so nervous at the beginning because he lacks enough practice.

A friend just reminds me to work hard in the weekend. He originally likes to set up 6:30 AM.




interview advice

July 14, 2018

Introduction


It is good advice I read from a Chinese website written in Chinese. A software developer with more than 5 years experience shares his advice on the onsite interview.

Here is the gist I created. I have to figure out the ways to get good understanding of his advice.

A short version of advice


I like to be creative, fist I copy the note to the current blog and then reorganize it to a short version here.


Friday, July 13, 2018

Infix expression design

July 13, 2018

Introduction


I spent last two days to look into infix expression. I like to know how and why infix expression is designed to allow open and close bracket to help and make it easy to parse using a stack.

I like to google and then find out.

Follow up 

July 14, 2018 10:30 PM

I played tennis today and then I figured out something for my blog on tennis court.

I like to give a good name for this infix expression design.  It is most cheapest way to use extra space to get optimal time complexity.

To design infix expression just uses those extra open bracket and close bracket, cheapest extra space to allow smart programmer to apply linear time to parse the expression, just use a stack to apply the storage for those unprocessed expression.





30 minutes running so fast

July 13, 2018

Introduction


I like to write down some notes about the algorithm I spent 30 minutes to work on. The graph algorithm should be a simple and easy one to write, but somehow I did not test the graph algorithm very well.

I like to spend 10 minutes or so in short future to write down some test cases for a simple graph algorithm.

Clone graph 


I like to study the algorithm called clone graph.

infix expression to construct binary expression tree

July 13, 2018

Introduction


It is my favorite thing to do to scan the code qucikly in less than 15 minutes. Here is C++ for the algorithm.


Using stack


The really important tips are to use stack, so the time complexity can be implemented using O(n) time to parse the infix expression. And the binary express tree can be built in bottom up way. The similar idea using stack can be see in multiple places.

The ) bracket is used to determine when to pop the stack and handle the operand and also operator.


Here is the gist I created how to use stack to parse the infix expression and then construct the binary expression tree.

Here is the output of stack working on a simple test case:

My bet was wrong


 I knew that stack is used on reverse polish notation. And it is widely used to parse the input. There is a hard level algorithm Leetcode 301 to parse parentheses, I did write 10 blogs on that. I also did work on hard level algorithm using more than 10 ideas.

 But the performance on 30 minutes is beyond my control. I could not think clearly using stack and stop on close bracket ), and then start to pop and then construct binary express tree from bottom up.

 What I did is to think about finding operator (1 + 2) so that I can use the string manipulation to get the result. I am not aiming highest potential I can reach in those 30 minutes.

 Through the performance, I understood that it is very important for me to calm down, and list all the options I have. Stack or not using stack, what is time complexity? Can I beat other people to write an optimal time complexity solution.

 I still remembered that I practiced a hard level algorithm on hackerrank and learn the power of using stack. The algorithm is called Reverse shuffle merge.

Actionable Items


Review all past practice using stack.

Here is the first one, Leetcode 109: convert sorted list to binary search tree.

Review one of solution using O(n) time O(1) space, the link is here.



Follow up


Most important is to understand the space is cheap, using space to expedite the time is always best choice, need to scale the problem in large expression. This time I failed to give it a try in 30 minutes using stack to get linear time complexity.

Dua Lipa - See in Blue (documentary)

July 13, 2018

Introduction


It is less than 10 minutes video for me to learn from a singer, what is her thinking process to start her career starting from 15 years old. The video link is here.

I really like the singer and how good she expresses herself using such good statements. Specially a talk related to hard work.

Take some notes




infix to postfix expression study

July 13, 2018

Introduction


It is such a great topic for me to pick up after I spent 30 minutes to write a infix expression parser. I understand that it is so important to lower down time complexity to linear, the only way I can do is to convert to postfix expression, and then I will not need to spend time complexity O(N^2) on the algorithm.

How far I can go on this topic?


There are a few resources I can easily find. I like to choose three good reading material first.





binary expression tree study

July 13, 2018

Introduction


It is called binary expression tree. I really enjoy to spend a few hours on this topic and write a blog to document my study.

Here is the wiki article. I like to spend 10 minutes to read again and write down some notes here.


90 minutes mock interview sharing

July 13, 2018

Introduction


It was my Wednesday 10:00 PM mock interview, I am the interviewer and the peer is very experienced programmer who is preparing facebook onsite interview. He likes to share the interview on mock interview platform, I like to support his decision.

The interview is 90 minutes, 3 algorithms involved. We had very good discussion and I really like the interviewee, he wrote anything I suggested, and I never saw any one wrote so perfect code before.

Website 


There are less than 30 showcases on the site: https://interviewing.io/. Here is the image to help find the mock interview.



Home sick - a song I like to sing

July 13, 2018

Introduction


It is the first time I start to search singers I may like long time. I found one for my summer time, and here is the song called home sick. The singer is Dua Lipa.

I have to find some songs for my tennis workout. I need to work on my summer sports planning and get ready to spend more hours on tennis court.

Here is the song I like to learn next week, and here is the meaning of lyrics of To be the one.




Wednesday, July 11, 2018

What is my motivation to work hard?

July 11, 2018

Introduction


It is a small research topic I did on tennis sports. Professional tennis player and what he/ she believes.

Because one of professional tennis players takes too much time on commercial thing, other professional tennis players think that she will not succeed as other do.

More than 30 minutes chat


I had chat with my friend Emma and we talked about what is my motivation. Do I believe in hard work? Do I believe in luck? or superstitions?

We talked about Carpe Diem, um tatoos professional tennis player put on her hand.




Counting down 48 hours

July 11, 2018

Introduction


I like to train myself this time using 48 hours. I like to go over as many as possible algorithms and data structures in 48 hours range. It is good ideas to go over some Leetcode algorithms, my past practice on hackerrank contest. I like to see the difference this time.

My belief is that using easy level and medium level algorithms to warm up is most efficient way.


Yesterday once more

July 11, 2018

Introduction


I like to use Carpenter song to remind me how sweat the feeling is. Yesterday once more. I got contacted by a very good software company on July 10, 2018.

I documented the birth of my coding blog. Why I started to write coding blogs to help myself starting from January 2015.

Now three years are gone. I have chance to learn something new again. I am so excited.


Graduation season

July 11, 2018

Introduction


It is so enjoyable to congratulate my ex-coach graduated from Tsinghua university master degree yesterday through wechat.com.

I should write something here to celebrate the graduation. Maybe I should copy a few bible verse to make a very good blog here.

Searching ...

Life is a treasure box

July 11, 2018

Introduction


I just could not believe that life is a treasure box. I felt so good to got a message from a peer met more than six months ago. The peer likes to practice with me this weekend on algorithm and data structure problem solving. I just could not believe that he offered me to practice together. He won ICPC region contest before.

I put together a post on github.com. I learn to publish on github.com and see if there are something new to learn. Here is the link.


Count substrings with same first and last characters

July 10, 2018

Introduction

It is the algorithm I am trying to search through Google about contiguous substring. I am  trying to find the optimal solution, but I could not find it. So I decided to study one of post here:

Count substrings with same first and last characters

Tuesday, July 10, 2018

Leetcode 171. Excel Sheet Column Number

July 10, 2018

Introduction


It is an easy level algorithm in Leetcode.com. I plan to review the algorithm quickly.

Leetcode 88: Merge sorted array

July 10, 2018

Introduction


It is an easy level algorithm but I like to practice one more time.

Leetcode 41: First missing positive

July 10, 2018

Introduction


It is a hard level algorithm. I spent 10 minutes to read the solution, and also reviewed my practice this year. I will write down something for the algorithm here.


Leetcode 61: Rotate list

July 10, 2018

Introduction


It is a medium level algorithm called Rotate list. I plan to spend 10 minutes to go over the algorithm in next 24 hours.


Leetcode: Meeting room II - sweep line algorithm

July 10, 2018

Introduction


It is the algorithm called meeting room II. I like to try to use sweep line algorithm to solve the algorithm this time. I will write down something here.


Leetcode 75: Sort colors

July 10, 2018

Introduction


It is the algorithm called sort colors. We can use non-comparison sort, counting sort should be a good solution since we only have three colors.


Leetcode 2: Add two numbers

July 10, 2018

Introduction


It is the algorithm related to linked list. I like to learn how to write a recursive solution, since I like to write a short solution.

Here is the code I read from one of blogs, I like to try it later.

Recursive and iterative solutions


I like to write the code to handle a few test cases in the following order:

1. One of lists is empty;
2. Add one node list together, no carry;
3. Make it work if there is carry, then I need to call the recursive function twice instead of once.

4. Think about how to extend the linked list to more than one node. Add recursive call function.

Here is C# code I wrote using recursive function.

I also spent 10 minutes to review iterative solution written in 2015, and I reviewed the code.

Version of code: 2015  iterative, link is here.
Version of code: 2018  iterative, link is here.

Actionable Items


One way to train myself to write a quick recursive solution is to write a prototype one first. Here is the one I wrote to show how to do it.

Based on prototype function, I just need to add the linked list with more nodes.

I did not think cleary last night since the prototype is more complicated than copy linked list with a random pointer algorithm. Since the prototype already involves one recursive function call.

Monday, July 9, 2018

Enjoy tennis sport

July 9, 2018

Introduction


I just could not believe that I had such great time to play tennis and then I like to spend extra 20 minutes to study a topic to improve my tennis sports.

Here is the post on quora.com I like to study.


Being professional



I also came cross the post how to be a professional tennis player. The talk about being professional is such a great one. I like to copy the talk here.

I like to find some good topics related to summer tennis practice.

Racket sports serve up health benefits.

The Surprising Benefits of Playing Tennis – Tennis Quick Tips Podcast 46

10 hard level Leetcode algorithms

July 9, 2018

Introduction


It is time to say good bye to the weekend. This morning around 10:00 AM I wrote down 10 leetcode hard level algorithms on the paper first, and then I started to work on those hard level algorithms.

What I like to do is to build a good habit to work on hard level algorithms. I have to plan to work on those 10 hard level algorithms in the weekdays as well.

The algorithms are Leetcode 483, 488, 493, 499, 502, 514, 517, 527, 546 and 522.


Alexa.com report

July 9, 2018

Introduction


It is so interesting to read report on alexa.com about my coding blog. Here is the report. Here is the comparison with another popular coding blog with a million view already.

Will continue.

Sunday, July 8, 2018

Alexa - check list for writing

July 8, 2018

Introduction


It is Sunday evening 11:57 PM. I did 10 minutes research and came cross this Alexa.com article. It is called check list for writing.

I like to spend 20 minutes to read the article and write down some notes here.


Leetcode 488: Zuma game

July 8, 2018

Introduction

It is a hard level algorithm called Zuma game. I like to spend 30 minutes to work on it today. Now it is 6:43 PM. I like to spend next 10 - 15 minutes to read the discuss about the algorithm.


Leetcode 483: Smallest good base

July 8, 2018

Introduction


It is the hard level algorithm called smallest good base. I spent 30 minutes to think about problems and last 10 minutes to read discuss. I started from 5:09 PM.


Leetcode 126: word ladder II

July 8, 2018

Introduction


It is the hard level algorithm called word ladder II. I wrote a few blogs in 2016, and I like to review my past practice, and also learn something new.

One of simplified algorithm is only to return one of the shortest transformation sequences.

Have a plan


I like to submit my code using Leetcode online judge this time. I did not submit any code back in 2016, even though I spent so many hours.

I like to check in the code I wrote in 2016 and put into github. I also like to read Leetcode discuss and find out ideas to write simple code this time. Here is C# code link.

Leetcode 129: Sum Root to leaf number

July 8, 2018

Introduction


It is the medium level algorithm called sum root to leaf number. My idea to solve the problem is to pass in prefix sum and use recursive solution. My mistake in my first attempt on sample test case doubles the value from 25 to 50.

Here is my C# code.

Leetcode 295: Find median from data stream

July 8, 2018

Introduction

It is hard level algorithm. I like to review the algorithm using Leetcode online discussion panel.


Leetcode 480: Sliding window median

July 8, 2018

Introduction

It is a hard level algorithm called Sliding window median. I like to work on the algorithm. The optimal time complexity should be O(N), N is the size of the array. How to manipulate the sliding window.

Leetcode 322: Coin change

July 8, 2018

Introduction


The algorithm is medium level. I also wrote an answer on code review more than one year ago. But I have not submitted any answer through online judge.

I am planning to work on the solution and also read some discussion as well.


Backpack problem

July 8, 2018

Introduction

It is time for me to think about the algorithm related to backpack problem. 

m个栈里面有不同面额的硬币,最多pop n次,peek()可以查看任一位置的值,而不仅是最顶的。那么可以取出最多的总值是多少?一开始懵逼了,不知道怎么下手。面试官给我降低难度,只有一个栈的情况,进一步,只有两个栈怎么办? 逐渐觉悟到用递归搜索去解决。按着这个思路代码写出来了。回家复盘的时候,经友人提醒,是多个分组的背包问题


Leetcode 64: Minimum path sum

July 8, 2018

Introduction


It is the medium level algorithm called minimum path sum. I have not submitted any code yet. I like to work on the algorithm in short future. Here is the blog I like to study quickly.


longest subarray with zero sum

July 8, 2018

Introduction


It is Sunday morning. I like to read one of post about onsite algorithms, and work on one algorithm called longest subarray with zero sum.

Ideas 


Two pointers cannot solve the problem. It can be preprocessed all prefix sum from left to right, and then use O(N) time to iterate each element and look up prefix sum with the same value.

What is the possible extended question?


Reference:
1. Onsite algorithms - gist is here.


Saturday, July 7, 2018

Leetcode: Number of islands II

July 7, 2018

Introduction


It is time for me to write code for the algorithm called number of island II. I have warmed up three times on the algorithms, and I like to write one using union-find algorithm.

I tried to give the algorithm number of islands II in my 10:00 PM mock interview. So I had chance to learn more about the algorithm together with the peer.


Blog to study


Here is the blog I like to read. I also will put some notes in Chinese to a gist first.

How to learn to code (quickly and easily!)

July 7, 2018

Introduction


It is very good 11 minutes video related to learn to code.


Languages 


Usually the programmer learns how to write code using a new language by himself/ herself. It is called self-taught.


Why I don't read news

July 7, 2018

Introduction


It is a good research topic related to news value. I like the topic and like to learn something from the talk.

Here is the video's link.

Thing to be considered


What is noise and signal, and try to filter out the information.

10 Year in the life of a software engineer

July 7, 2018

Introduction


I found that it is very good entertainment to see a person can have such freedom to choose to work, travel and have a person life as well. Very good video and very good time to enjoy 10 minutes video.

The video link is here.


How I taught myself to code again (and got a job at Google)

July 7, 2018

Introduction


It is very good topic about teaching and learning to code again. I like the topic. It is 10 minutes video to watch. Here is the link.

Very good thinking process


It is such nice sharing in the forest. I like the sharing.

Computer science fundamental is very important.

Top 3 programming languages in 2018

July 7, 2018

Introduction


I like to spend 20 minutes on this video. It is talk about languages used, top 3 languages can be looked up through the website.


Mock Google interview (for software engineer job) - coding & algorithms tips

July 7, 2018

Introduction


It is 20 minutes video talk and I like to write down some notes. And I also like to study other videos provided by the engineer - Patrick Shyu.

Taking notes from the talk


3:00  Good consideration pros and cons of time and space. Remember show the impact.
Validate a lot of work, craft the story, as soon as some one asks you. Check the interviewer's reaction.

Do not make it too long. Keep it quick. Just 45 minutes. First 15 minutes talking about experience. Next 30 minutes about white board about the algorithm.

5:27
Ask an algorithm on the white board:
Given a grid, find maximum grid. It is commonly asked called flood fill.

How you solve?

Data structure, algorithm and ...

7:12
Tree view, you will be evaluated to have ability to rise a senior engineer level.
You do not have foundation to be a senior level. Tree traversal, and complexity ...

8:20 PM depth first search, double first search (can be BFS), it can be iteratively solved.

Leave it open ended. Grid data structure, 2-D integer.

To a junior, give a start pointer.

10:12  How interesting people can get those neighbors. You have to have a lot of bound check. GetNeighbors, and ..., save your much more time.

Delegate the way to do checking. Hashmap or hashset, what is your hashset. Sometimes you can have a red flag.

12:00 recursive function - 10,000 iteration - how big the grid will be? Push cells to stack or queue.

13:55 Write small font. Bring my own pen.

Tradeoffs, space and time tradeoff


14:42 It should be done before you write the code.

 You need to be able to understand time and space tradeoffs.

Talk about iterative solution vs recursive. At front it is best. We are just coding, we do not know what it is end? Time complexity.

Each cell just once.
16:02 - It is not really you got the answer. Whether you are confident on the answer, how you can do it.

17:25 Experienced interviewer.

Worst time to give the answer of the question.

17:59 Tradeoff between space and time complexity. Evaluation of your code, did you know tradeoff? Did you consider creating data structure? How is your efficiency? How is your jerk? Enthusastic? Take feedback. Overall value skills.

18:03 Your coding good, object-oriented programming. Did you consider using your own data structure?

Friday, July 6, 2018

Code Jam's kickstart

July 6, 2018

Introduction


It is my research task to read Lalit Kundu's quora posts, I spent a few hours to read one by one. I came cross this video talk 30 minutes, and I like to watch the video. Here is the link.

Take some notes


5:00 - 11:00
Talk about solving a problem using a graph. Very good explanation.

11:00 - ?
There is a talk about topological sort algorithm given by Lalit Kundu.

15:13/ 31:55
Some caveats

Not every Kickstart problem will reduce to a known problem or algorithm!
Many problems require creativity and insights
It may help to think through the problem and your algorithm carefully before writing any code

19:57 PM thought process?
So other people's mileage may vary here, do not know what to do right away. Just apply a small individual case and spot some pattern.

Lalit: make it a general form -

20:00/ 31:55 - you can summarize the problem in one statement. Explore certain paths, dynamic programming, greedy algorithm. Good strategy is do not code until you have ideas how to solve it.

I do not code it until I finalize and prove the algorithm.

21:30 It can save you a lot of time to have the correct idea before you write the code.


Quora reading time

July 6, 2018

Introduction


It is time for me to find some good question and answer to read. Here is the one. In order to show support, I also wrote an answer for the question.

My answer


Here is my answer to the question "How can I overcome the difficulties in implementing Data Structures?



Thursday, July 5, 2018

Leetcode 862. Shortest Subarray with Sum at Least K

July 5, 2018

Introduction


It is hard level algorithm. It can be solved using deque, sliding window and O(N) time complexity, N is the array length.


Wimbledon update

July 5, 2018

Introduction


It is the summer time. And it is so important for me to spend time to watch some Wimbledon sports every day.

Day 3 video is here.

Wimbledon grand slam

July 5, 2018

Introduction


It is the summer time and also it is time for me to play sports after the work. I like to spend 20 minutes to watch Wimbledon as well. I like to get more educated on the tournament.




How to decide if the interviewee can go to next round?

July 5, 2018

Introduction


I set up 4 weekdays 10:00 PM as an mock interviewer. I try to get connect to the community and help others to train their algorithm and data structure. I need to work on a few things after I replay and listen to my voice through the conversation. One thing I have to learn is to let more people to go to next round since I use one hard level algorithm to test interviewee, it is hard for a person to solve it in less than 30 minutes first time.

I find so much joy to talk to people and help me to recover from the daily full time work stress last few days. It is so much fun to talk about intern, coding, algorithm, and some tips related to ascending stack technique today.

I will make a check list how to evaluate a peer and decide if I should let him/ her go to next round. I will write down some notes. It is a good study topic for 10 to 20 minutes.

A check list





My second coach

July 5, 2018

Introduction 


I like to write a blog for my second coach this past June, 2018. I was too busy to write a blog about his help and tremendous generous sharing through three mock interviews with me.

Here is the github page I created to document my three mock interviews with my second coach.