Saturday, July 28, 2018

weekend planning - easy tree level algorithms

July 28, 2018

Introduction


It is time for me to plan to work on easy level tree algorithms. Here is the link and I use it to find all easy level tree algorithms I plan to work on this Saturday.

Over ten tree algorithms


I like to write down every easy level tree algorithm by name. I am planning to work on those algorithm today.

Easy level algorithms I completed: 687, 110, 572, 2235, 101, 671, 543, 108, 563, 100, 538, 606, 226, 104, 872, 617.

Easy level algorithms for me to work on:
111, 112, 501, 437, 589, 270, 700, 429, 257, 107, 590, 404, 559, 653, 637, 669


687 32.7%Easy
111 33.9%Easy
112 35.5%Easy
501 37.8%Easy
110 38.9%Easy
572 40.3%Easy
437 40.3%Easy
235 40.6%Easy
101 41.0%Easy
589 41.2%Easy
270 41.3%Easy
671 42.1%Easy
700 42.1%Easy
429 42.4%Easy
257 42.4%Easy
107 43.2%Easy
543 45.2%Easy
108 45.7%Easy
563 46.9%Easy
590 46.9%Easy
404 47.9%Easy
100 48.2%Easy
538 48.8%Easy
559 49.4%Easy
606 50.2%Easy
653 50.3%Easy
226 54.4%Easy
104 56.2%Easy
637 56.3%Easy
669 58.1%Easy
872 65.0%Easy
617 68.1%Eas


Where to find most hard working people?

July 28, 2018

Introduction


It is so surprising that I found a few people with thousand submission last year on leetcode, and I also read his post on one of algorithms I worked on in the evening of July 27, 2018. I know that I am out-of-date on this topic, where to find most hard working people? I also need to find some facts to support my training decision, work on Leetcode easy level algorithms.

Two role models



Those people with thousand submission last year should be my role model. I like to list two of them here, I like to train myself as they do using Leetcode online judge.

Engineer Tian Yuan:

Leetcode 687 Longest univalue path -> discussion link ->
https://leetcode.com/tyuan73/ -> Linkedin profile, solved 652/ 869, 1168 submissions last year
(Follow up on May 22, 2019 solved 783/1045, 737 submission last year, 2209/3697)

Engineer Naveen:

Leetcode 687 longest univalue path -> discussion link ->
https://leetcode.com/naveenkothamasu/ -> 1641 submissions last year, solved questions: 345/869

(Follow up on Sept. 5, 2019, soved 610/1778, contest ranking: 10932/112269)

Easy level algorithm training so amazing 


I just could not believe that the training of Leetcode easy level algorithms is so amazing. I also have the chance to learn from most hard working people as a software engineer.


Leetcode easy level algorithm training progress report

July 28, 2018

Introduction


It is time for me to write a report for my last two report Leetcode easy level training. I have worked so hard and then I submitted more than 30 algorithms in two weeks. This is the first time I did submit 30 algorithms in less than two weeks.

Progress report



Here are some facts:

1. My leetcode profile is here.  130/869, 147 submissions last year.
2. July 17 - July 31, 2018 two weeks practice github folder containing all source code. Here is the link.

I had chance to read more content about algorithms, and those content could not find using Google or other resource. I find most hard working people who know how to train themselves so hard.

I have so many issues with those easy level algorithms. I just could not enumerate how many times I stumble and how many things I like to learn from those algorithms. I have to push myself hard and also try to move forward with new algorithms.

I change my attitude, I do not stay on same emotion too long. I need to go to work, solve an algorithm and write code. I have to take risk to implement my idea first, and then talk to myself to simplify the idea, and beat the odds to finish in less than 10 minutes. Sometimes I give up and start a brand new ideas.




Friday, July 27, 2018

Leetcode 687: Longest univalue path - recursive design learning

July 27, 2018

Introduction


It is an easy level tree algorithm. I spent over 60 minutes to write and learned from other shared source code. It is very interested algorithm and I like to learn.


My learning


I chose one of the discussion and write my C# practice here.


Follow up 


7/28/2018 10:22 PM

One thing I can do is to go over the example, and walk through the example, give the explanation of the recursive function design. Also try to explain the algorithm using less than 5 minutes.

       5
    /      \
   4       5
 /   \        \
1   1        5

The idea is to traverse the tree using preorder, visit each node once. I think that it is very good practice to explain how to design a recursive function to count how many nodes from the root node to have same value continuously to leaf node.

Follow up 


August 1, 2018

I continuously used the algorithm to give the interviewee to work on one more than two times. Both of them had difficult time to come out the clean solution in less than 45 minutes. One of them has issue to work on recursive function and design the recursive function on the value cross the root of tree.

I was asked why I spend my time to work on interview, help others to prepare and learn. I explained to the peer that I also learned from his performance. When he asked me what to recurse on, if left side path or right side path, actually it is maximum of left side path and right side path. I could not tell the answer right away. I know that I just memorize the study code, I really have to give myself time to review and think and come out fully understanding as well.

I shared my thoughts with interviewee, there are hundreds of solution for this tree problem. I could not verify every line of code for you. But I did challenge you the design of recursive function is basically wrong. You cannot recurse on something cross the root node.

So good experience to be an mock interviewer on interviewing.io. It helps me to learn the algorithm I just practice. If I do speak out my mind, the interviewee did agree with me.

Sometimes it is hard for me to give feedback honestly, since the peer may be under pressure to try to get startup interviews. The feedback is important for them as well.

Leetcode 687: Longest univalue path - faulty design

July 27, 2018

Introduction


It is easy level tree algorithm. Now it is 11:51 PM, I believe that I spent over 60 minutes to work on the algorithm.

With faulty design, I managed to write a solution to pass 43/68 test cases.

My practice


Here is my C# code.


Leetcode 671: Second minimum node in a binary tree

July 27, 2018

Introduction


It is an easy level binary tree algorithm. I spent 22 minutes and then fixed the bugs a few time and passed online judge.

My practice


Here is my C# code.

Highlights of bug fix:

1. Line 48, if current value is smaller than the smallest one, then current is the smallest, previous smallest one should be second smallest one. I forgot the previous smallest one should be replaced existing one.

2. Line 50, duplicate value with smallest one; the value should not be counted toward second smallest one.

Follow up


August 29, 2018  10:40 PM

I gave the algorithm to the mock interviewee on interviewing.io, and also I had chance to review other solutions.

I like to share my solution on Leetcode discuss first. And also I like to write another solution based on given constraint, the root node is smallest one if there are two children.

Leetcode 543: Diameter of binary tree

July 27, 2018

Introduction


It is an easy level tree algorithm. There is a linear solution O(N), the idea is to traverse the tree using preorder, and then calculate the maximum path value along the way. In the recursive call of maximum path value, all possible diameter can be calculated each step.


My practice


Here is my C# practice with optimal time complexity.

I had so many issues to work on the coding. I like to share the submission results and remind myself to be humble, and work hard on easy level algorithms first.


Ideally I should spend less than 10 minutes and submit once to get accepted. Here are highlights I had in more than one hour practice.

1. Line 34, global variable needs to reset. Online judge reported error one node tree return 3.
2. Line 52, 53, left and right variable should be used, but my mistake is to call the same function again. Time limit exceeded.
3. I aimed optimal time complexity solution, but the code has some issues...
4. I wrote time complexity O(N * N) solution, and then ...




Backtracking

Backtracking leetcode discussion link is here.

Thursday, July 26, 2018

Coolest aunt this August

July 26, 2018

Introduction


It is time for me to review what I have done as a sponsor to support an immigration case. Am I coolest aunt this August 2018?

Recently I worked on the immigration paper, I had chance to review my paper work and provided my late mother's old passport page copy and her visa to United States in 2001. I like to show to immigration officer that I cherished the relationship with my mom and I had real life experience with my mom and my siblings.


Coolest aunt this August


I try to be the coolest aunt this August 2018.

I know that I am very independent, have good critical thinking skills.

I did my sponsor application project by myself starting from 2016 October, and it took me more than 12 months until the paper work was accepted in October 2017. My young sister kept telling me to hire a professional to help, but I just said that I solved problems just by failing again and again.

Am I coolest aunt this August?


Follow up 

July 31, 2018

No law is well-written and it should be case by case. In order to save the time and cost, only way I can survive to support an immigration case is to do it by myself. Find ways to show the genuine relationship with my late mom and her grow-up children.




What is luck?

July 26, 2018

Introduction


It is my small research topic tonight for 10 - 30 minutes. Now it is 11:40 PM. I had a mock interview yesterday, and the peer talked about something about luck. Hard working is important, but sometimes you have to depend on the luck. The performance can fluctuate so much.

Recently I reviewed one of coaching video in my blog, talking about training hard. When you train yourself, you have less distraction, but when you are on tournament, there are so many distractions. Try to focus more when you train yourself.

I did find issues on my training on Leetcode 114 tonight.

There are a check list for me to work on. For example, Does the candidate enjoy finding multiple solutions before choosing the best one? Detail see my blog here.


What is luck? 





My baby step on easy level tree algorithms

July 26, 2018

Introduction


It is so true that I have to go through Leetcode easy level tree algorithm training first, 10 hour or 20 hours until I understand the basics again. I did practice 5 easy level tree algorithms on July 25, 2018. I could not believe that my baby step is 5 easy level algorithms a day. I felt so much joy to work on those easy level tree algorithms.

Also I had chance to meet a peer through mock interview at 10:00 PM on July 25, 2018. The peer gave me advice saying that if you do easy level algorithm very well, you will have chance to work on medium level or hard level algorithm quickly. There are so many ways to solve easy level algorithms, once you master those ways, you will much fast learn the hard level algorithm. The peer demonstrated good problem solving skills on tree algorithms.

My baby step


Here is the folder I created on github to celebrate my dedication to easy level leetcode algorithm practice. It is the first time I learn to be humble, and try to work independently first, and then seek the ideas through Leetcode discussion.


Actionable Items



I like to figure out ways to expedite my problem solving skills on easy level tree algorithms. I need to train myself another 10 to 20 hours.



Leetcode 110: balanced tree

July 26, 2018

Introduction


It is an easy level tree algorithm. I struggled more than 30 minutes when I practiced, so I asked the interviewee in mock interview, he solved less than 10 minutes in July 25, 2018 10:00 PM. I understood that it is so important to meet people and learn from others.

Here is the gist for C++ code. I will write a C# solution based on the code later.


Leetcode 114: Flatten binary tree to linked list - Every road leads to Rome

July 26, 2018

Introduction


It is most famous verse "Every road leads to Rome", and I learn from my mock interview experience. Every peer solves binary tree problem different ways, I have met over 100 people to work on binary tree. But every road leads to Rome. I have to be open to ideas, and make every idea work in my practice as well.

Story begins this way


Idea A -> failed a few times over 30 minutes -> Idea B -> succeed in less than five minutes using idea B-> felt happy over 30 minutes -> feel not right -> go back to idea A, and try to make it work. Less stress -> really learning begins here

Idea A -  left subtree as a linked list, which should connect to right subtree as linked list.
Idea B - using two global variable, previousNode, currentNode.


It is a medium level tree algorithm. I spent more than two hours to work on the algorithm tonight. I could not make the idea work more than 30 minutes, I try to make the left subtree's last node connect to the right child. I knew that my code was too complicated.

I have tried all possible solutions in the first hour, I could not make it work. And then I solved the algorithm using two global variables - previousNode, currentNode first. After 20 minutes, I decided to go back to original idea, and I felt so relaxed. I like to make my original idea work as well.

Here is the submission records. Tonight at least I struggled more than 20 minutes on this idea until I tried to write simple code, changed the idea to use two global variables, 1 hour, 37 minutes ago with one succeed submission. Now it is 10:55 PM, 10:30 I submit a solution and passed online judge using the original idea.





My submissions of Leetcode 114


Here is my solution submitted on June, 2016. I need to review the solution again.

Here is my solution which passes Leetcode online judge, submitted in July 25, 2018 at 9:10 PM. The idea is to use two global variables.

Here is my solution which passes Leetcode online judge, submitted in July 25, 2018 at 10:30 PM. The idea is to find left subtree's last node, and make it connected to right subtree linked list.


Follow up 


7/28/2018 9:11 AM
I like to show the image to compare two submission, left side is the problematic code, right side is the code which passes online judge. How to think and solve the problem?



I am trying to write down some notes here to coach myself, next time I should be careful.

First, choose the preorder traversal. Visit root node first, and then recursive call of root.left and root.right. Here when the root node is visited, assign root variable to the global variable currentNode on line 11.

Next, I need to find the place when the currentNode is the last node of left subtree, and then I need to set it next point to right subtree linked list's first node. Here line 15 I put comment saying currentNode is the last node in left subtree.







1takeinterview.com

July 26, 2018

Introduction


It is a good idea to spend 30 minutes to look into the interview coaching website. I like to figure out something through my 30 minutes study.

Here is the website.


Leetcode 114: Flatten binary tree to linked list

July 26, 2018

Introduction


It is a medium level tree algorithm, I spent over 30 minutes to struggle to write the code. I believed that I did write some code in June but I never tried the solution on the online judge. This time I really had difficult time to figure out the solution.


My practice 


I finally calmed down. I tried to write most simple solution as possible. I did look at the result, it is preorder traversal to output all the nodes in the binary tree. All I have to do is to take care of the current node. If there is a previous node, previous node's right child is current node; the current node's left child will be null pointer.

Here is my C# practice.


Sliding window minimum

July 26, 2018

Introduction


It is my 10:00 PM mock interview. I had chance to give the peer second algorithm to work on called sliding window minimum. He gave me the optimal solution but I could not fully understood the algorithm. So I decided to prove it the correctness using k = 3.

Mock interview discussion


I modified the transcript to make it more readable. Here is the transcript.



To summarize, the sliding window minimum algorithm can be solved using two scan of array, one from left to right, second one from right to left. And then each scan the minimum value is calculated after the elements of array are divided into windows with size k.

Follow up

Feb. 12, 2019

I just learned that the interviewee joined Google this Feb. 2019. I like to review mock interview, and also I like to write an algorithm based on his idea as well.

Wednesday, July 25, 2018

Leetcode 98 Validate Binary search tree

July 25, 2018

Introduction

It is an easy level tree algorithm. I reviewed my practice over two years ago, and then I rewrote the code.

Here is my code.


Leetcode 572: subtree of another tree

July 25, 2018

Introduction


It is an easy level tree algorithm. I wrote a C# algorithm based on my understanding, and it passes online judge.

Here is C# code.


Leetcode 563: Binary tree tilt

July 25, 2018

Introduction


It is an easy level algorithm. I wrote a solution based on my own understanding, and it works fine with online judge.

Here is my C# code.


Leetcode 538: Convert BST to great tree

July 25, 2018

Introduction


It is an easy level algorithm. The idea I chose is to traverse the tree by visiting right child, root node and left child this order.

Here is my C# algorithm.


Leetcode 110: balanced binary tree

July 25, 2018

Introduction


It is easy level tree algorithm. I worked on the algorithm and try to choose O(N) time complexity algorithm, by visiting all the nodes in the tree once. I ended up to spend over 30 minutes and then the code has multiple bugs and a few test cases failed.

I like to document my learning on the tree level algorithm and encourage myself to practice more on easy level algorithms.

My practice


Here is my C# code with multiple failed test cases.


Tuesday, July 24, 2018

How smart you can control your expense?

July 24, 2018

Introduction

It is 11:39 PM. I like to do 10 minutes study about controlling expenses. My argument is that a smart programmer should be very smart to control his/ her expense. We all know that the software programmer as a career is not easy one. Specially I had met a few people on the job market and I understand how stressful it is.

My understanding is that very good software product can be built by so many iterations. If the living expenses and job security is questionable, then the software programmer will not have too much determination to optimize the product.

I need to learn better to control my expense. I like to do some study on this topic as well.

Actionable Item


Next time do not spend over $300 dollars on any project, set a cap value to $300.00. I have to count tax paid, all living expenses paid in order to save those money.

I need to plan carefully. Money cannot buy success.


Leetcode 96. Unique Binary Search Trees

One week for new habit

Introduction


I like to write down if I can build a new habit to code every day, using leetcode online judge to train myself.


How many days does it take for me to build a habit to write code daily?

I find out that it is easy to write code for easy level algorithms on Leetcode.com. I like to write easy level algorithms to train myself in next two weeks. Also I like to do some small research how to build a good habit to write code daily.

One week 24 algorithms


I wrote three hard, two medium, 19 easy level algorithms in one week. I train myself in a week using those 23 algorithms.

I started from July 17 to July 24, I wrote 23 algorithms and also passed Leetcode online judge. The algorithms are

Easy level
63, 88
113, 198,
202, 203, 205, 231, 234, 277, 278, 283, 290
303, 326, 343, 349, 387,
438,

Medium level
556
648

Hard level

132
273
301

In order to pass Leetcode online judge for the above 23 algorithms, I did a lot of work and surprisingly I was so happy to write code for those algorithms. I am a happy problem solver.

Leetcode 301 Remove invalid parentheses


It is hard level algorithm. I worked on the algorithm more than 12 months ago I have to make algorithm simple as remembering one test case, how to come out the story how to solve it, for example, hard level algorithm 301. Here is my practice documented in the blog.

Leetcode 648 redudant connection



Also I learn that I spent time to write down my frustration and learning more than 6 months ago, but at that time I did not learn that it is most important to write the code for the algorithm and pass online judge.

To build a new habit to write code and run against Leetcode online judge.

Monday, July 23, 2018

Great coach videos

July 23, 2018

Introduction


It is such good videos about Leetcode algorithms. I like to spend time on those videos.

https://cspiration.com/

Leetcode 132: Palindrome partition II

July 23, 2018

Introduction


It is hard level algorithm and it is very interesting problem. I spent over one hour to study all the discussions but I am not sure if I understand the problem.

I found one video and then finally I understood the min cut meaning. Here is the video I really figured out the problem.

My practice


I like to read two discussion. One is here. The second one is here.

This video teaching is an excellent one. And the source code is here. I will write one using C# as well.


Time spent


9:00 PM - 11:28 PM

I could not believe that I had luxury to spend over two hours on this algorithm.


Sunday, July 22, 2018

careercup.com website

July 22, 2018

Introduction


It is my summer drill for next few weeks. I like to choose one of four biggest software companies and then work on algorithms and train myself to think hard.

I start to use careercup.com website and search using keyword facebook, sort by latest date.

Here is the link I am using tonight.


Leetcode 556. Next Greater Element III

July 22, 2018

Introduction


It is a medium level algorithm, and it is not easy to come out the idea to find smallest larger integer. I plan to write the algorithm in short future.


My practice 



It took me over 60 minutes to write the code. I submitted a few times before the code can pass online judge.

Here is the C# code.


There are a few issues to slow me down in the coding process. I will look into later.

1. Content is wrong. Try to call .ToString() method from a char array, and then output is not char array content. I fixed the issue on line 56, using string constructor instead.
2. Confuse myself on line 76, current variable name is confusing. It is better called digit, which should be declared as int, int digit = s[i] - '0'
3. ...

Actionable Item


I do not know how to come out the idea by myself next time, I read the hint and analysis from geeksforgeeks.com "Find next greater number with the same set of digits" this time. The article link is here.

I have to push myself hard and figure out the idea by myself next time. The analysis is so well written in the article. Here is the analysis:

Input:  n = "218765"
Output: "251678"

Input:  n = "1234"
Output: "1243"

Input: n = "4321"
Output: "Not Possible"

Input: n = "534976"
Output: "536479"


Following are few observations about the next greater number.
1) If all digits sorted in descending order, then output is always “Not Possible”. For example, 4321.
2) If all digits are sorted in ascending order, then we need to swap last two digits. For example, 1234.
3) For other cases, we need to process the number from rightmost side (why? because we need to find the smallest of all greater numbers)

Following is the algorithm for finding the next greater number.
I) Traverse the given number from rightmost digit, keep traversing till you find a digit which is smaller than the previously traversed digit. For example, if the input number is “534976”, we stop at 4 because 4 is smaller than next digit 9. If we do not find such a digit, then output is “Not Possible”.

II) Now search the right side of above found digit ‘d’ for the smallest digit greater than ‘d’. For “534976″, the right side of 4 contains “976”. The smallest digit greater than 4 is 6.

III) Swap the above found two digits, we get 536974 in above example.

IV) Now sort all digits from position next to ‘d’ to the end of number. The number that we get after sorting is the output. For above example, we sort digits in bold 536974. We get “536479” which is the next greater number for input 534976.


Count down the weekend hours

July 22, 2018

Introduction


It is 8:30 PM and I have three hours left to say goodbye for the weekend. I like to work on 1 to 5 10 to 20 easy level algorithms just by quickly scanning the problem statement, and thinking about a few minutes, and checking discussion panel.

Easy level algorithms


Here are easy level algorithms I like to work on. Leetcode 292, 303, 326, 342, 344, 345.




Leetcode 290. Word Pattern

July 22, 2018

Introduction


It is easy level algorithm called word pattern. I did not catch the constraint until my code failed the test case: "abba" with "dog dog dog dog". The problem statement is written using the following phrases:  bijection. Given example 4 is the test case I failed in my first writing.

Here is my C# code passing online judge.



Leetcode 283: Move zeros

July 22, 2018

Introduction


It is an easy level algorithm called move zeros. The time complexity should be O(N), N is the array's length.

Here is my C# solution.


Leetcode 278. First Bad Version

July 22, 2018

Introduction


It is an easy level algorithm called First bad version. The binary search algorithm is applied and also the lowest index is found for the first bad version.

Here is my C# code.


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.