Wednesday, February 14, 2018

Float numbers and operators

Feb. 14, 2018

Introduction


It is 10:00 PM mock interview. I gave the second algorithm for the peer to work on. The peer is very smart and took hint quickly, after he got the hint to keep maximum and minimum value, he wrote the optimal solution in less than five minutes.

I just could not believe my eyes. And after mock interview the peer told me that he is preparing onsite interview next week.

Code review


Here is transcript of mock interview.

Leetcode 124: Longest consecutive sequence

Feb. 14, 2018

Introduction


It is the hard level algorithm and also it can be solved using dynamic programming method. It is called longest consecutive sequence.

Study notes


I wrote down the study notes. Here is the link.


Leetcode 300: Longest common subsequence

Feb. 14, 2018

Introduction


It is the medium level algorithm and can be solved using dynamic programming. This dynamic programming algorithm is getting easy since I have worked on the dynamic programming algorithm deletion distance over ten times last 11 months, and one of solution is to use longest common subsequence.

Algorithm study


I spent around 20 minutes to go over one blog and wrote down my study note. Here is the link.

Back pack algorithm (II)

Feb. 14, 2018

Introduction


It is the traditional dynamic programming. It may take me a few minutes to come out the solution if I study the algorithm very often.

Here is my study notes.

back pack algorithm

Feb. 14, 2018

Introduction


It is the most popular dynamic program algorithm. I also wrote down the notes how to analyze the problem in a simple recurrence formula. Here is my study note.


Dynamic programming article

Feb. 14, 2018

Introduction


Chinese is my mother language. I like to see if I can learn dynamic programming quickly by reading some article in Chinese.

I started to review dynamic programming from the most popular blog in Chinese written in 2014. Here is the blog.

Study notes


One thing I like to do is to go over the blog word by word, and organize it better for me to read next time.

Here is one of articles I read and I saved the content to the gist.


Tuesday, February 13, 2018

Leetcode 115: Distinct Subsequences

Feb. 13, 2018

Introduction

It is time for me to read more Leetcode algorithms in next week. I like to go over 150 algorithm and see if I can read the algorithm blog and come out the idea by myself, or I can try to understand the hint given by the blog.

I like to work on hard level algorithm Leetcode 115: Distince subsequences, based on the analysis from the blogger. Here is the blog link.




Leetcode 154 algorithm review

Feb. 13, 2018

Plan to read Leetcode algorithm blogs written by top ranking blogger one by one. Here is the link.


4 sum algorithm

Feb. 13, 2018

Introduction


It is 8:00 PM mock interview. I spent 18 minutes to write 4 sum algorithm based on the advice from the peer, do not use extra space, using two pointer technique,  I wrote the algorithm. The total interview took us 38 minutes.

Code review


Here is C# code.

Design a chess game

Feb. 13, 2018

Plan to read the design question on stackoverflow.com. Here is the link.


Design a parking lot

Feb. 13, 2018

Plan to read the post on stackoverflow called design a parking lot. Here is the link.

Leetcode super talent

Feb. 13, 2018

Introduction


It is my interest to find good mock interview algorithm. I like to look up those Leetcode algorithm and determine which ones to study.

Today I came cross this website. I could not believe that the graduate student of Tsinghua university already completed over 600 algorithm practice on Leetcode, and also wrote down the summary for most of algorithms.


Feb. 27, 2018

I could not believe that I was so busy last 2 weeks. But I came cross the blog and then decided to read the leetcode algorithm one by one. My ideal of

training is to cover as many Leetcode algorithm as possbile. I like to train myself to think more about analysis, review the code and also ask myself a

few questions for each algorithm.

The beautiful journey began here.

The Leetcode blog I chose to read for my first one or two hours:

Leetcode summary 201 - 300



#285
#286
#287
#288
#289



Actionable Item


I like to go over as many algorithm as possible. Go over the algorithm and think about for the idea. Try to find some interesting problems to work on. Get used to training, analysis algorithms daily and also keep myself to solve new problems 5 to 6 of them every day.


Do not stay on the same algorithms too long. I already work on the same set of algorithm around 30 of them on mock interview, I know that it takes time to learn and good to learn from so many people.

I also need to try new algorithms every day so that I can get used to think and push myself hard every day.

Here is the blog to go over 500 Leetcode algorithm by the Ph.D., ex-Microsoft and Snap software engineer.



Leetcode 128: Longest Consecutive Sequence (II)

Feb. 13, 2018

Introduction


It is the hard level algorithm. I chose to study the algorithm since the blogger wrote a blog abut Leetcode Spiral Matrix, and today I chose to review my blog in 2015, and then I had chance to review the summary of Leetcode graph problems.

Algorithm 


The blogger talked abut using graph and depth first search technique to find optimal solution based on time complexity O(n). The array does not need to be sorted, and the graph including all elements in the array can be expressed in a hashset.

Here is the gist I created to study the blog. And here is the C# code I wrote based on Java code.

Analysis of the algorithm


What I like to do is to go over the analysis of algorithm written in Chinese in the above blog. And then I like to highlight a few things, and make some arguments.

Constraints:
The array is not sorted. It is integer array.
Need to find longest consecutive subarray.

Ask:
longest consecutive sequence - greedy algorithm

What is consecutive sequence?
You can start any element in the array, and then search its left side and then right side and find all consecutive sequence include the number.

O(nlogn) time complexity algorithm

这道题是要求出最长的整数连续串。我们先说说简单直接的思路,就是先排序,然后做一次扫描,记录当前连续串长度,如果连续串中断,则比较是否为当前最长连续串,并且把当前串长度置0。这样时间复杂度是很明确,就是排序的复杂度加上一次线性扫描。如果不用特殊的线性排序算法,复杂度就是O(nlogn)。


Think in Graph


其实这个题看起来是数字处理,排序的问题,但是如果要达到好的时间复杂度,还得从图的角度来考虑。思路是把这些数字看成图的顶点,而边就是他相邻的数字,然后进行深度优先搜索。通俗一点说就是先把数字放到一个集合中,拿到一个数字,就往其两边搜索,得到包含这个数字的最长串,并且把用过的数字从集合中移除(因为连续的关系,一个数字不会出现在两个串中)。最后比较当前串是不是比当前最大串要长,是则更新。如此继续直到集合为空。如果我们用HashSet来存储数字,则可以认为访问时间是常量的,那么算法需要一次扫描来建立集合,第二次扫描来找出最长串,所以复杂度是O(2 * n) = O( n ),空间复杂度是集合的大小,即O( n )。

Leetcode 282: Expression add operators

Feb. 13, 2018

Plan to work on hard level algorithm Leetcode 282: Expression add operators.

Monday, February 12, 2018

Learn to be a good interviewer

Feb. 12, 2018

Introduction


I am getting better on practice to be an interviewer. This is the seventh mock interview and I worked as an interviewer as anonymous interviewer.

I know that it takes time for me to build up a new skills. So I start early and work on diligently four times a week. And I just finished seven of them.


Getting better is possible


Here is the feedback I got on Feb. 9, 2018 mock interview.


Canada family day long weekend

Feb. 12, 2018

Introduction


It is a busy long weekend. I only spent 2 hours on tennis court on Feb. 12, 2018 from 4:00 pm to 6 pm. It was still chilly but I enjoyed so much to play tennis and still felt that I am very healthy and energetic. I have not run too much the whole weekend until in tennis double match today.


Mock interviews


I practiced over 14 mock interviews through the long weekends. I could not believe that I met so many talent people and then I had chance to continue to work on the algorithm, and also learn so many things through the mock interviews.

Here is the picture to show what I did.




Launch school

Feb. 12, 2018

Introduction


It is another mock interview this Monday 6:00 PM. I had chance to work with a peer and then I was interested in the peer's JavaScript ability. He did have more time to learn JavaScript and then I like to figure out why.

Launch School


I met over five peers to work on FullStackAcademy boot camp. And the peer shared me with his experience, he did research to convert his career to software programmer. He chose the Launch School.


Actionable Item


Look into the courses provided by Launch School. Here is the web link. The launch school is much cheap compared to boot camp. And the student can spend as much as need to go over all the courses. The peer shared with me that he spent over a year to finish all those courses. I just like to say that he is very smart young person who represents United States hard working young generation.

I am so happy to have chance to mock interview with him today. Proud that United States will become much stronger country since those hard working young generation.


Wechat sharing with my family


我上周末模拟面试一个美国小伙子,  31岁. 有工程管理经验. 爱打篮球. 自己转行做计算机软件开发. 名牌大学毕业. 我面试过七八个麻省哈佛, 转行学计算机, 参加四个月强化班, 一万二千美元.
这小伙告诉我, 费用太高. 他选了自己控制进度, 叫https://launchschool.com/, 每月200美元, 他读了一年多. 这个学习计算机用多种途经, 他学得很好. 节省了一万多美元, 而且学生是全世界. 课程水平高.  很多中国学生. 
你说中国留学生如何竞争, 除非你可以进四大软件公司. 要么和美国年轻人竞争. 他们是有语言优势, 教育优势, 工作经验.
美国的前途在这些勤奋的年轻人手中. 我很高兴地帮助他们成长, 成才.


Leetcode 776: split binary search tree

Feb. 12, 2018

Plan to work on Leetcode 776 in short future.

Here is my C# code. It is easy to figure out the solution after I worked on the similar algorithm, please take a look the algorithm called binary search tree inorder successor to test candidate confidence.

Leetcode 54: Spiral matrix

Feb. 12, 2018

Plan to study Leetcode 54: Spiral matrix python solution. Here is the link.


Leetcode 54: Spiral Matrix

Feb. 12, 2018

Introduction


It is 12:00 PM mock interview. I had to work on Spiral matrix algorithm. So I spent around 20 minutes to write a solution based on my last practice.

I learned the lesson on interviewing.io on January 23 2018. The lesson is that I have to take mock interview seriously. Follow the interviewer. If I am asked to find the alternative solution, then I have to fully use those 40 minutes to come out the solution. Work on it, and define the requirement, and address the issues, come out the design, techniques to solve the problems first.

Code review


Here is my C# code.


Find best position to host the party based on Manhattan distance

Feb. 12, 2018

Introduction


I do not expect that I will learn the algorithm from the peer after the mock interview. Actually it is very good experience to learn that the peer can solve the problem using very good reasoning skills, related to quick select algorithm.

For my understanding, it is like applying counting sort or bucket sort, you decide where to place the position, count how many increments and decrements for each move.


Algorithm discussion


Here is the algorithm.

Follow up 

May 8, 2018

The peer got Google full time job starting this May. I am so excited to get connected to him.

June 19, 2018
Here is Leetcode 296.

One of his blogs:
https://blog.csdn.net/xudli/article/details/49420623

Here is blog about geeksforgeeks.com.
https://www.geeksforgeeks.org/sum-manhattan-distances-pairs-points/

Deletion distance dynamic programming

Feb. 12, 2018

Introduction


It is BC family day and I booked 10:00 AM mock interview. I wondered last night who will practice mock interview in the day time of Monday. I was wondering if I should work on something else, go out to play tennis, walk around the park, go shopping of fresh fruit and vegetables.

I started to work with the peer on the algorithm called Sudoku Solver. It is so much fun to work with the peer on this algorithm. I did one a few days ago on the engineer in silicon valley area, and I like the peer quick thinking and also very good communication skills. Specially when the peer asked me if everything looks good on my side.


My mock interview


I had to solve deletion distance using dynamic programming. What I did is to go over the example first, and then I explained how to solve the problem row by row.

Here is C# code. The peer advised me to optimize the space to O(m + n) instead of O(m * n).





Here is the graph I drew and then I worked with the example to explain the algorithm. I found out that I have more time to explain the algorithm using the graph and walk through the example slowly to explain the algorithm, in case there is any question from the peer, I can stop and then explain more.

I also start to learn that the coding part is less challenge compared to explanation of the algorithm.

Smallest substring containing all unique keys

Feb. 12, 2018

Introduction


It is so much fun to play mock interview. I met the same peer fifth time.

After the mock interview, I gave the algorithm to the peer to solve, and I am busy working on my hackerrank contest algorithm.

Last minute, after ten minutes to give out the algorithm, I found out that I made a mistake on the constraint. The array should include non-negative elements only. And the peer came out the solution I could not understand.

The problem is to find a continuous subarray with the given sum, and then the solution is to apply dynamic programming using O(n) time to get the prefix sum from left to right, and then use two pointer techniques on an ascending array.


Code review


I chose to skip my algorithm, and asked to study the peer's solution. Here is C# solution I like to review and then rewrite later.






Sunday, February 11, 2018

Cut a strip - hard level algorithm

Feb. 11, 2018

Introduction


It is the hard level algorithm and I already spent over 60 minutes to think about the algorithm. I like to make it my favorite hard level algorithm. This is Sunday night Feb. 11, 2018 10:32 PM. I wrote down the blog while I mocked interview the peer.

It is hard but I like it


I like to work on the analysis of the algorithm first. I did just download a few algorithm lecture notes and try to identify what is the algorithm. The algorithm is the hard level algorithm on week of code 36. Here is the link.

Follow up 


Feb. 20, 2018

I like to read the solution and then study some of code submission as well. I looked up all submissions scoring 70 and then I found the blog to read.

Here is the blog of the algorithm.

Idea to solve the algorithm


I just copied the idea from the above blog, and then look into some keywords:
题意
给一个矩阵,可以将其中大小 1 × x (1 ≤ x ≤ k) (纵横均可)变成 0,求操作后最大子矩阵和。
题解
  • 如果没有修改,那么就是枚举两行,预处理列的前缀和后就转化为经典的最大子段和了。
  • 现在这个最大子段和问题,多出了一次修改,用 dp 记录一下修改有没有用过即可。
  • 问题在于要在一列的一个区间中贪心地去掉长度不超过 k 的子段,使得剩下的和最大(也就是子段和最小)。这个过程在枚举行的下界时用单调队列维护一下,求出最小子段和。
  • 因为去掉的不一定是列的一部分,还可能是行的一部分,所以要转置后再计算一次。
  • 由于操作是必须进行的,矩阵中所有元素都为正数需要特判,强行去掉矩阵中的最小元素。



How to Think about algorithms - Loop Invariants and Recursion

Feb. 11, 2018

Introduction


It is such a great answer on quora - Is it worth to hire a Google engineer to help me to prepare for Google interview?

I like the web link of Algorithms and Data structure free books. Here is the link. I also find a book to download and plan to read it.

How to think about algorithms?


I plan to read the book. Here is the book link.

Week of code 36

Feb. 11, 2018


Introduction


It is so difficult for me to find hours to work on the week of code 36. But I like to give it a try. Now it is 6:27 PM. I try to push myself to get to spend time to work on hard level algorithm.

I just booked a 10:00 PM mock interview. Now it is 7:20 PM. I like to prepare a dinner for myself. So I will have two hours 40 minutes to spend time to think about an algorithm.

Cut a strip


Now it is 8:20 PM. I have 80 minutes to work on the algorithm. It is hard level algorithm.

Leetcode 780: reaching points

Feb. 11, 2018

Introduction


It is most difficult algorithm I heard. The dynamic programming or recursive solution could not pass Leetcode online judge. I plan to study the algorithm in short future.

Here is the link.

Swift means sweet

Feb. 11, 2018

Introduction


Swift language is chosen by young generation programmers and they like to work on ios app etc. I was explained by the peer through the mock interview. I rated that the peer is one of top performer in my last 160 peers last eleven months.

It is my decision to start a new round of mock interview using ID: beet after I finished the round using ID: apple. I also chose to interview using Swift language, since I practiced one time with a peer using Go, I like to learn new things and stay out of my comfortable zone this round.

This is the first time over 160 mock interview that I met a peer who used Swift in the mock interview. As a matter of fact, he was the first person who asked me to give him time to look at his algorithm before I started to code my algorithm Leetcode 10: regular expression matching.

And also the peer shared his Swift code of Leetcode 10 after I performed my algorithm. And then the peer told me that he solved the problem differently, and I asked him to explain it to me. And then I had chance to learn Swift language from him, and also I had chance to ask question on the implementation. I learned to ask questions and identify the recursion zero time, one time or more than one time in the code. I was so surprised that I just learned a new way to solve the problem. It is an iterative way, and it is to go over pattern string and perfect solution. I really enjoyed the learning.


Swift code


It is kind of sweet for me to learn a new language. I learn starting from my most favorite algorithm. I just could not believe that the teaching and learning can happen so quickly.

Here is the swift code. I added comments to highlight the b* pattern repetition zero time, one time or more than one time.


Leetcode 10: regular expression matching algorithm

Feb. 11, 2018

Introduction


It is 10:00 AM mock interview. I had to work on the algorithm of hard level, Leetcode 10: regular expression matching algorithm. I told that it is not easy to write in 30 minutes, I did exactly 30 minutes, wrote analysis and also wrote the code, fixed the index-out-of-range error, and then passed all test cases.


Mock interview 


I wish that the mock interview platform has some recordings like interviewing.io so I can replay how I did less than five minutes to go over the test case and explained my approach.

I just quickly pasted the analysis I did in mock interview here. And then I will write a few sentences to match my presentation in the mocking interview.


Add caption
What I did is to go over the example with text string "acd" and pattern string "ab*c", and then drew a matrix with text string and pattern string. I did not make the choice, and by accident, I chose the pattern string in the right top corner, and then it is to go over each pattern char from left to right in the row. And also I explained to the peer that I will go over the base case first, which are first row and first column. After that I will go over each row and then I did go over the row on line 72, using text "a" and compare to each pattern string and fill the value with True or False.

Specially I explained the case with text "a" and pattern string "ab*", and b* will apply zero time. So the result should be true. T(0) is the symbol whereas 0 stands for pattern repetition number of times.


Analysis and C# code 


Here is my analysis and C# code. I explained to the peer later on how many practice I went over this algorithm, so many people in the world help me to go over the algorithm. I also watched the peers to perform the algorithm more than five times.

I still remembered that the Christmas day in 2017 a young Chinese graduate student performed the algorithm almost perfectly, I could not believe that he could do it perfectly in front of my eyes, I did go through several times with experienced programmers in the world, how they struggled to write recursive function multiple times. I did ask a lot of questions.

Just two days ago, the peer shared me the news he joined LinkedIn as an intern through the wechat. It is a side story. But I just wrote down to remind myself that teaching and learning is so efficient and once I know that a young graduate student can perform, I believe that one day I also can perform as well.




Saturday, February 10, 2018

Say hi to the city of Seattle

Feb. 10, 2018

Introduction


I have met over 10 people from the city of Seattle in anonymous interviews last two months, however I only met less than five people in the city of Vancouver area.

Every weekend I have chance to meet people from the city of Seattle, and also I have chance to learn so many exciting things happened in the city.

I met a programmer from the city of Seattle, and then I advised him to play one of Hackerrank contest. It is fastest and easiest way to get the feeling to algorithm and data structure, and then you will think about the algorithm and data structure all the time in your daily activities.


Say hi to New York again

Feb. 20, 2018

Introduction


It is true that I met a peer from New York this morning 12:00 PM mock interview. I already met over 10 people from New York. I started to learn one thing a time from people working in New York industry.

It is fun and also people are more active to reach out to other people as well.

New York style


I did hear a few things about New York. How things work in the city of New York. Today I also learned a few things through discussion of JavaScript coding of a H-tree algorithm.

Here is JavaScript code.

Since the peer told me that he has over 10 - 12 years ruby on rail experience, so I asked him the question how he designed the JavaScript function, basically it is like functional programming style. const drawHTree = (x, y, length, depth) => {. 

I asked the peer to extract variable top_y, bottom_y, left_x, right_x four variable, and then I asked the peer to write to DrawLine the length of line and declare a variable for totalLines. 

I asked the peer to  count how many H-tree by steps, and then he quickly came out the time complexity. 





How to make a successful mock interview as an interviewer?

Feb. 10, 2018

Introduction


It is the sixth mock interview on the second anonymous platform, so I had chance to meet programmers from top ten companies in west coastal area and also graduate students from top universities, and then I had chance to get some feedback about the algorithms I choose, and the behavior issues I have to correct.

First of all, I should give the interviewee the agenda, including how many algorithms I should give. This is the advice I got from Feb. 9, 2018 mock interview. I do not want to scare the interviewee when I ask the interviewee to stop the first algorithm, and I like to move on to the next algorithm.

My goal is to test how confident the interviewee is, how good the interviewee is on algorithm and data structure problem solving. I will continue to ask and then see if I can find any major issues through the interviewee. Since the interviewees are with experience both sides, and also with very good education, so usually I just pay more attention to learn something through the experience.

People varies in terms of soft skills, and learning new things outside the work. Sometimes people can not hide if they do not practice algorithm and data structure long time, like catching up in a month of two.

Algorithm


The interviewee asked me where to find the resource about the algorithm I asked in mock interview. I know that the interviewee is very confident and also independent thinking. So in order to prepare an algorithm to be my mock interview algorithm, I also try to build a profile for the algorithm. I share the algorithm float number and operations on the stackexchange.com website. Here is the link.

I continuously study one algorithm called spiral matrix, Leetcode 54. First time I learn that it takes so much time for me to catch up so many ideas and then I know how smart people are to get the good idea to survive in a mock interview and write a perfect working solution in ten minutes.

Yesterday the interviewee took over ten minutes to read the problem Leetcode 54 and came out the idea, and then he tried to use extra space to avoid so many edge cases. I really like the idea, it is something I am looking for in mocking interview.

I honestly told the interviewee yesterday that some one did much better than him, passed through all four algorithms I gave to him in first 35 minutes, and he did 30 minutes system design interview as well. If you work for a big company, basically you are competing with your coworkers. The anonymous interview is supposed to be hard, difficult to pass the interview. Do not get frustrated if you get low rating. I just make sure that you are guided to the optimal solution, so you learn something and do not waste time on mock interview.

The precondition is that I also have to learn the mock interview algorithm from all the interviewees, I have to build depth and breadth of knowledge of the algorithm.

What I have learned as an interviewer


I did find one thing through the mock interview. I have to learn how to take turn to express my idea and also try to catch the right time.


Educative.io

Feb. 10, 2018

Introduction


It is another 10:00 AM mock interview. I had good time to write a recursive function called minimum path sum from root to leaf node, and also I had chance to watch the peer to perform a recursive function using depth first search.

Advice


One advice I got is to watch courses on educative.io. The peer took two courses, one is algorithm, one is system design.


Friday, February 9, 2018

Leetcode 54: Spiral matrix - based on directions

Feb. 9, 2018

Introduction


I keep learning the spiral matrix algorithm through Leetcode discussion, and then I came cross the discussion of Leetcode solution based on the directions.

Here is the discussion note I like to share. I read carefully about the analysis and then write down and make some modification, so I can follow closely the thinking process of the author.

Analysis based on directions


I like to go over the discussion here as well. Here is the C# code. Also I like to add this solution to the question I asked on stackexchange.com so that I can get some feedback later on.

Thursday, February 8, 2018

Leetcode 54: Spiral Matrix

Feb. 8, 2018

Introduction


One more solution is here based on using two variable to switch direction clockwise. I read the idea from Leetcode 54 discussion, and then tried to write one using C# language.

One of ideas is to go over as many Leetcode discussion as possible, and then I will vote the idea I like and actively share my feedback. Because I like to use this algorithm for my mock interview as an interviewer, I like to do as many research as possible.

Please write at least ten ideas using C#. Be well prepared and learn one algorithm very well. I can  use the algorithm to tell who is real talented programmer in the world.

Using two direction variables

Here is C# code.


Leetcode 54: Spiral matrix - think recursively

Feb. 8, 2018

Introduction


It is my idea how to train myself in the practice. It is to involve the discussion of Leetcode. Every algorithm I should give out 10 votes for 10 different ideas, and also write C# code based on the idea.

I did some research based on my practice of Leetcode 301 recently, and I found out that my practice has some issue. And I wrote a blog how to learn a hard level algorithm on Leetcode.com.


Recursive solution


I studied the solution today, and I like to write a C# code based on the idea. It is the great warm up of recursive function, and also nice to review base cases in the design of recursive function. Here is the C# code.



Wednesday, February 7, 2018

Easy, medium and hard level algorithm as a combo

Feb. 7, 2018

Introduction


It is so interesting to meet a peer fourth time in less than three months starting Nov. 2017, and I had to work on Sudoku solver algorithm the third time. The first time I did write the algorithm, second time I skipped, and the third time I skipped, but the peer gave me favor to ask me a few more algorithms. He asked me if I like to have a medium or hard level. I explained that I should handle hard level algorithm since I am not a new graduate, so he started from easy, and then medium and the hard level three algorithms in the row. The whole discussion took less than 40 minutes.

House robbery easy level, extend algorithm medium level, and word square hard level three algorithm.

Here is the transcript. I will look into those algorithms.

The pseudo code is written by the peer. I got the idea and explained to the peer. But the peer likes me to write down the pseudo code, so he did for me instead. Because I was too nervous, I could not believe that I figured out all three algorithms correctly, but I could not write clearly as I did in explanation using pure English words. Certainly the peer was very good at whiteboard interview, he could write very clearly than I should have done as an interviewee.

House robbery


Leetcode 198 easy level, Leetcode 213 medium level


Word Square


Here is Leetcode discussion link.



How to learn a hard level algorithm on Leetcode?

Feb. 7, 2018

Introduction


I chose to work on Leetcode 301: remove invalid parentheses, and then I spent 30 minutes to work on the algorithm last Saturday Feb. 3, 2018. And this past Tuesday night I browsed all the blogs and then I found that I worked on the algorithm last July 2017. So I was so surprised and then I had to look into what is going on. How come I do not have any clue that I work on the algorithm over hours.

I was so surprised to read my own blog and then just amazed that how time can take away everything. Hard work and long journey of coding, design and study. Here is the blog dated on July 2017. I even wrote an answer in discussion and then got 3 reputation. I did not aware that I had positive reputation, last time I checked I only have zero reputation.

How to learn a hard level algorithm? 


It is important to practice again and again on the same hard level algorithm. My last practice in July 2016 seems not working very well, because I could not remember too much detail about how to write recursive function, tips and tricks.

This time I changed the plan. I like to focus on more on ideas. I tried to write more than five blogs for each idea of the algorithm, and write down my own notes for each idea. Hopefully I can learn more things from one hard level algorithm.

There are so many algorithms, I can not work on a lot of them. Just get familiar with hard level one.

What I like to do is to leave 10 discussions comment for other people's post in leetcode discussion panel, and also vote up to 10 ideas to encourage people sharing. Get involved more about sharing ideas on the hard level algorithm. Do not be biased on ideas.



Leetcode 301: Breadth first search and pruning (VIII)

Feb. 7, 2018

Introduction


It is interesting to read the gist I prepared for the discussion of breadth first search and how to prune the algorithm. Here is the link. And here is the C# code.


Leetcode 301 - How to speed up the algorithm? (VII)

Feb. 7, 2018

Introduction

I spent time to read the discussion how to speed up search. Here is the gist.


Leetcode 301: Remove invalid parentheses (VI)

Feb. 7, 2018

Introduction

It is interesting to read and study the solution based on breadth first search. Here is the gist I prepared for my study.

It is time for me to warmup the skills using Queue to solve an algorithm. Here is the C# code.


Leetcode 301: remove invalid parentheses (V)

Feb. 7, 2018

It is such a good workout that I wrote a C# code based on one of solutions in Leetcode discussion. Here is my C# solution.


Leetcode 301: remove invalid parentheses (IV)

Feb. 7, 2018

This is one of solutions I like to study. First I prepare the study note for myself. Here is the link.

Leetcode 301: remove invalid parentheses (III)

Feb. 7, 2018

I like to review the study note later for this algorithm. It is written in Chinese. Here is my gist file.


Float number and operators algorithm

Dec. 7, 2018

Introduction


It is the fifth mock interview on the platform, and I am the interviewer. I have to be very careful since my last mock interview I got very low rating, the peer said that he wasted time, and I learn something quickly.

I am still trying to use the same two algorithms, but I like to make sure that I have to lead the peer to the optimal solution, this way if I am real interviewer, interviewee will like to work with me. Also I have to show up as the professional, act like a real interviewer.

Julia interviewer 


As an algorithm daily mock interviewer, I am lazy to think about the solution using dynamic programming. Today the peer wrote one dynamic programming solution for the algorithm. I learned quickly, it is so easy, nothing different from deletion distance algorithm I HAVE practiced over 20 times.

I know that sometimes I have this false impression and think that I am super talented.

Here is the python code using dynamic programming, I reviewed the code. The code passes test case [1, 12, -3] with maximum value 33.


The power of the algorithm


I try to practice nice as an interviewer, and then it turns out that the interviewee is super talented. He passed Google onsite interview recently. I just could not believe that I have learned how to behave in mock interview, I just need to follow the interviewee and watch the video how he answered each question.


Bayesian statistics


Do you like to read the performance report using Bayesian statistics. Definitely it is learning experience for me, I really enjoy the ride so far. I met top performers, over 10 years programmer working on search engine, a person can write a compiler (I guess), and a young master graduate who can pass through google onsite.

It is not hard for me to learn one algorithm very well. I just try out for difference interviewees and then learn from the experience.

spiral matrix algorithm

Feb. 7, 2018

It is my decision to start to work on Leetcode 54 Spiral matrix again. I like to go over all possible solutions through Leetcode discussions, and then vote some of them, and write C# version.

One thing I can do is to work on the same algorithm but use various approach. And I need to understand what the difference is, what makes impact on time consumption on writing, easy to avoid edge cases handling, and what is the production code.

After I practiced over 10 times on the algorithm starting from March 2017 to January 2018, I found the weakness of my practice.

Tuesday, February 6, 2018

Binary tree at least 2 path sum same

Feb. 6, 2018


Introduction


I spent 20 minutes to review the post on code review, and then I wrote the solution based on the review. Here is the code review link, I asked the question over one month ago.

Code practice


Here is the C# code integrated with all the reviews. I use the algorithm to warm up recursive function and think about using it in anonymous interview in short future.




Float numbers and operators

Feb. 6, 2018

Introduction


It is the algorithm I like to use in anonymous interview. I used it four times, and I started to think about more on the algorithm.

Brute force solution


Here is the brute force solution. This algorithm is really challenging and the peer complained to me on Feb. 5, 2018 that I should lead the interviewee to the optimal solution, otherwise it is waste of the time. The algorithm is for interview of principle lead or programmer, not even for senior.

There are a few issues to handle besides using recursive function, flat preference, max and min used to reduce the numbers from four to two, and also using memoization or dynamic programming will lead to optimal solution.

I will continue to use the algorithm and see if there is a super talent interviewee, and I can learn from the experience how to write the optimal solution.


Being interviewer: Deletion distance and long common subsequences

Feb. 6, 2018

Introduction


It is 8:00 PM mock interview. I had chance to learn a way to solve deletion distance using long common subsequences.

The idea is to find the longest common subsequences in two strings, for example, "heat" and "hit", the common subsequence is "ht", so the distance is "heat" and "hit" length sum minus 2 times length of common subsequence "ht". It is 7 - 2 * 2 = 3.

Code review


Here is Java code.


Leetcode 214: Shortest palindrome (I)

Feb. 6, 2018


Introduction


It is hard level algorithm and I like to learn the algorithm. It is called Shortest palindrome.

30 minutes thinking


Since the algorithm is hard level, I plan to practice at least 10 times. Today I spent 30 minutes to thin k about the solution, and address possible issues in the brute force solution.

Follow up

Feb.15, 2018

I did spend over 30 minutes to read the discussion, and then wrote C# solution based on Java code. I did not fully understand KMP algorithm yet.


Deletion distance dynamic programming

Feb. 6, 2018

Introduction


I still have difficult time once a while in terms of solving dynamic programming solution. The underneath recursive design of dynamic programming takes more time to practice.  I had a mock interview last weekend and the peer showed me his way to solve the deletion distance.

It is such nice learning experience from the peer. The code is written in Java and the link is here.

Most of important is that the peer showed me how he proved that recurrence formula is correct. Here is the transcript of the analysis.


Follow up 


I asked the peer in mock interview and then we discussed the formula why distance("heat","hit") = distance("hea", "hit").

Here is the discussion:

 //$dog and $frop,
  //$hit, i =   3 $heat, j = 4
  //f[$hit][$heat] = f[$hi][$hea]
  (f[$hit][$hea] + 1)
  (f[$hi][$heat] + 1)
  (f[$hi][$hea]  <- minimum
    min(f[$h][$hea], $f[$hi][$he]) + 1
  )


Let me write down the explanation given by the peer on March 12, 2018. First let me read his explanation and then figure out his reasoning.

First the peer thinks that it is better to add extra char to stand for empty string "", using '$' char.

There are 3 choices to determine the deletion distance between two string "$hit" and "$heat". There are three choices, in other words, here is the expression:

f[$hit][$heat] = Math.Min(f[$hi][$hea], f[$hit][$hea] + 1, f[$hi][$heat] + 1),

We should be able tell that minimum one is f[$hi][$hea].

Follow up 


July 9, 2018

The peer contacted me to ask practice together. I was so surprised since he won ICPC regional contest in 2012. It is the first time I have a peer to practice together with highly competitive skills in contest.

I just quickly looked up his review back in Feb. 3, 2018 6:00 PM. What I did is to check date connected on linkedin, and then found the mock interview round login, and then looked up algorithm. And then I found the blog, and mock interview feedback.


Ready for a new week

Feb. 6, 2018


Introduction


It is so exciting to change my goal for my algorithm and data structure practice. I start to learn from the mock interviews, and try to find things to help me to be a better person as well.

I had 12 mock interview from last Friday to last Sunday.

Practice highlights


I tried to teach a dynamic programming solution in mock interview and got some good feedback from the peer. Learning is so much fun and I also had chance to learn how a young graduate learns to handle a difficult dynamic programming solution.

I struggled on word count practice and actually I wrote i++ instead of i-- on line 33, and it took me more than 5 minutes but I could not spot the error. The peer is a computer science PH.D. student and he told me that if the index-out-of-range, you not need to check the pointer null. So reasoning is something I have to work on to narrow down the possibilities.

Through the practice I learn that it may be a good idea to build a habit to write a loop in ascending order and then change the inside statement of for loop instead. After mock interview, I tried to compare with my last successful practice and then identify the issue. Programmer time is no longer valuable if I have to spend time to find those trivial error since I need more strong analysis skills and also willing to apply to the bug fix.

I also observed an experienced programmer and learned how he troubleshooted his code and fixed bugs in less than 5 minutes on this binary search algorithm.

I also wrote a sorting algorithm and then noticed that the API should not be called swap two index's value, instead it should be called moveFromOneToAnother. The practice is here.

I also had chance to learn from the peer who has more than three years pythons experience. She showed me how good she can solve the binary search algorithm in this practice.


The valuable lesson to be a good interviewer

Feb. 6, 2018

Introduction



I never expect that I have to learn how to be a good interviewer until I finished 10:00 PM mock interview today. I got the feedback from an experienced programmer.


Code review


I have to review the code the peer wrote and also need to think about the feedback I got.

First algorithm is about Spiral Matrix. I did review the code and the code is very good.

Second algorithm is about float number and operators, I had to review the brute force solution. I did learn something from the code as well.

My feedback


It is hard to learn to be a good interviewer. I have to learn to focus on the basics and remove my bias.

The interviewee wrote very readable code and also very easy to work with. He did show his solution on the first algorithm Spiral matrix, the code he wrote demoed his very good analysis skills and high coding standard in his daily practice. The second algorithm is float numbers and operators, and then the peer wrote a solution but failed to pass test case [1, 12, -3], and then the peer asked for the hint, and then he came out the idea by himself to write a brute force solution using O(N^4) time complexity and also space O(N^4). The interviewee also taught me something as an interviewer, what I should learn. For example, I have to leave impression to the person, first the difficult level of the algorithm, is the algorithm for senior developer or junior developer. There are several areas the interviewee can improve, like coding style, communication skills, like algorithm analysis of the second algorithm. How to come out the optimal solution, reduce the time complexity from 4^N to 2^N? Based on the conversation after the mock interview, I think that interviewee taught me a good lesson to be an interviewer. I decide to let him go to next round.


Feedback from the interviewee


I have to make mistakes in order to learn to be a good interviewer.

Here is the feedback. Please close your eyes.

Would you want to work with this person? No
How good were the questions? Waste of time
How helpful was your interviewer in guiding you to the solutions? Not helpful at all
Help your interviewer get better!
Please put more thought into the questions you're asking others. Usually there are multiple ways to solve any problem - you as interviewer should be fine with any of the ways interviewee solves posed problem.


Play with the code


It is unbelievable that the interviewee wrote production ready code, so I changed the code to C# programming and ran the test case, it works for [1, 12, -3] with maximum value 33, the C# code is here.

I am not sure how the interviewee came out the design and wrote almost perfect code for a brute force solution. I continuously played the code and added some comment to look into those variables. Here is the C# code with some comments.


Monday, February 5, 2018

Algorithm study

Feb. 5, 2018

Introduction


It is so much fun to learn from a person by reading his website. I decided to read the book Element of programming interview, and then I found myself really enjoy to read the website of the author Tsung-Hsien Lee.

Algorithm teaching

Feb. 5, 2018

Introduction


I made the choice based on the peer's recommendation in my last weekend mock interviews. I decide to read the book called Elements of programming interview in Java. And then I started to read preface of the book on Amazon.com. I started to read about two authors. The first one is top ranking university computer science professor, I really like the website, specially with the notes the professor shared when he studied in the college. Those handwriting notes just brought me back to the college age, and the hardworking classmates of Shanghai Jiaotong university and their notes.

I do have very good notes as well. I took a math graduate course back from 2010 to 2014, I like to go back to Florida one day and see if I can find my Introduction to cryptography course home work, I like to share them on my blog as well.

Plan to read the website http://users.ece.utexas.edu/~adnan/


A great professor must be a good student when he is in the college. 

Sunday, February 4, 2018

Find smallest substring containing all keys

Feb. 4, 2018

Introduction


It is the algorithm I have to write for my 10:30 PM mock interview. The peer was very helpful and I had 30 minutes to complete the analysis and code, I did fix the grammar error in last minute and pass all test cases.

I can tell the difference. Since I understand the process of sliding window containing substring, how the left pointer can slide through if the substring contains all keys. I had one practice in January and then I got a few advice to optimize the algorithm. This time I could write the algorithm much quickly.

The peer advised me to speed up coding if I can.

Code review


The C# code is here. The peer advised to add extra variable to store the start position of substring, I added variable on line 21 called startIndex.




10 minutes to be interviewed

Feb. 4, 2018

Introduction


It is the game I play after the mock interview. Today after the mock interview, I gave two questions and asked peer to solve. One is spiral matrix and another one is maximum number of chunks. The peer is very experienced programmer, went to onsite facebook last year, second round Google phone screen, and since last 12 months he finished 300 algorithm on leetcode.com. I just saw the big difference compared to me, since he worked so hard on 300 algorithm recently, it is so easy for him to follow the hint to work on spiral matrix to write a simple while loop solution, it only took him less than 10 minutes to come out a total different solution.

After 20 minutes, I asked him to give me one algorithm to be interviewed.

10 minutes to be interviewed


Here is the transcript for my performance. I just could not believe with 4.9 out of 5.0 reputation, I continuously in the row this afternoon partnered with three programmers, with good intern experience or education background, with 4.0 GPA master graduate student. I think that it is so easy to learn thing quickly through the discussion.

I definitely learned something today.


Elements of programming interviews in Java: The insider's guide

Feb. 4, 2018

Introduction


It is hard decision to choose what to work on. It is a busy year, I just started to subscribe frontendmasters.com, but I find that it is hard for me to sit down watch a few hour of videos. It takes time to learn new things, I need to practice after I watch something.

Today the peer of my mock interview shared with me a book, he read the book and bought a paper copy; so he can read the book all the time.

The book is called "Elements of programming interviews in Java: The insiders' guide". This is the second time in less than one month two peers recommend me to read the book. One got Google onsite interview, one had facebook onsite interview less than one year.

Elements of programming interviews in Java


This will be my book. I like to find my most favorite three algorithms in next 30 days.


Saturday, February 3, 2018

Binary search algorithm

Feb. 3, 2018

Introduction


It is so interesting to know that mock interview is shorter than ever before. I met a peer who had intern experience with top software companies, and then he only spent less than 10 minutes to write the code and pass all test cases.

Both of us finished mock interview algorithms in less than 30 minutes.

Binary search algorithm


Here is Java code related to binary search.




Binary search tree algorithm

Feb. 3, 2018


Introduction


It is another mock interview at 4:00 pm, I spent around 15 minutes to analyze the algorithm and write the code. I worked on the binary search tree algorithm called Find inorder successor, and the peer shared with me his advice, it is also easy to check first left parent instead of comparing the value with parent node's value.


Code review


C# code is here.


New algorithms please!

Feb. 3, 2018

Introduction

It is time for me to set up a goal to work on more algorithms from Leetcode.com. There are over 600 algorithm on leetcode.com, new questions almost come out every day.

It is time for me to learn from the peer to prepare for onsite interview, I met a few people to prepare for onsite interviews. I met a peer one week ago, and he shared with me his Google document last month practice. From Dec. 1 to January 18, he practiced more than 30 algorithms on Leetcode.com. He is preparing Google onsite interview.

I finally spent 30 minutes to go over those algorithms, and then select some problems and decide to go over those algorithm. One of my favorite algorithm is called Leetcode 351: Unlocked Android App.

Mock interview


Mock interview is easy to continue right now for me. I have worked on those algorithm over ten times.

In order to push myself outside comfortable zone, I have to start to work on new algorithms. There are over 600 Leetcode algorithms, I have only worked on more than 100 algorithms.



Array of array products

Feb. 3, 2018

Introduction


It is the time to write the algorithm in less than 10 minutes. The algorithm is called Array of array products. Once the dynamic programming idea is used, all I have to remember is to do one multiplication from left to right iteration, but from right to left iteration, two multiplications are needed, one is to multiply the left product with right product, and then apply dynamic programming to right product using one multiplication.


Code review


Here is C# code.


Recursive function design talk

Feb. 3, 2018

Introduction


It is the third time I met the peer on mock interview platform. The peer worked on the algorithm root to leaf path sum minimum value, and then the peer explained to me his design in five minutes.

Tail recursion, local state, global state


The peer explained to me his idea of solving the problem. Local state is prefixSum variable, global state is minSum variable.

Here is the C# code.


60 minutes to reach out the community

Feb. 3, 2018

Introduction


It is the best time in the morning for me to reach out the community, I had 10:00 AM mock interview and I met a young graduate student in United States, and then I had to work with her to find a solution using binary search. Based on my past practice, it is very easy for me to give out some practical advise. I also enjoyed the learning process of Java programming language.

Code review


The idea used in the code is to find the pivot index in the array, the element's value is smaller than previous one, or it is the first one in the array.

After the pivot index is found, the normal binary search can be applied.

The Java code is here, I reviewed the code to remove index-out-range bug in binary search algorithm.

Java Array.binarySearch API end index is exclusive, so the peer fixed the bug to add one in the input arguments.

After the mock interview, the peer told me that she really likes the mock interview experience. She learned a few things from me. Also I shared the website called frontendmasters.com to her.

It is amazing that the new master graduate student is aiming to web development, and learn react framework and try to use mean stack to do development.

Largest smaller binary search tree key

February 3, 2018

Introduction


It is 10:00 AM mock interview and I had to work on the algorithm called largest smaller binary search tree key.

Analysis of the algorithm


To search the key in the binary search tree, we do not have to traversal the whole tree, all we have to do is to start from root node and then go right or left, until meeting the dead end. For example, the node does not have left node but we have to check smaller value, or the node does not have right node but we have to check larger value. 

I made so many mistakes in past practices, and I remembered the time I was so nervous and then think about largest smaller, how to keep the largest one in the set of numbers. Since the value of smaller one is found, those numbers are in ascending order, only one variable is needed to keep current one. 


Code review 


Here is the C# code.


Leetcode 301: Remove invalid parentheses (I)

Feb. 3, 2017

Introduction


I like to work on a hard level algorithm on leetcode.com. Also I do not like to rush and find the answer as I do sometimes. Through the learning experience of Leetcode 10: regular expression matching, I know that it may take me 10 practice before I can fully understand the hard level algorithm.


First 30 minutes


On Feb. 6, 2018 I had chance to work on the algorithm called Leetcode 301: removed invalid parentheses. I like to write down the notes and see if I can find the answer through the first 30 minutes work.





Leetcode 679: 24 Game

Leetcode 503: Next Greater Element II

Leetcode 490: The maze

Leetcode 351: Android Unlock Patterns

Feb. 3, 2018

Plan to work on the algorithm. Read the blog here first.


Friday, February 2, 2018

Leetcode 425: Word Squares

Leetcode 272: Closest Binary Search Tree Value II

Leetcode 42: Trapping Rain Water

Feb. 2, 2018

Plan to work on hard level algorithm Leetcode 42.

May 23, 2018

I could not believe that I could not come out the idea to calculate the rain water when I was asked by the interviewer on May 22, 2018 8:30 PM. I asked one of Chinese graduate student to help me, give me some mock interviews and this was the first algorithm he asked me.

I talked about descending stack, and the interviewer asked me why it is the descending stack. And also the interviewer asked me to give out the correct brute force solution. I noticed that my brute force solution is also not correct. I need to find left boundary for the current bar which should be maximum height of prefix elements.

Here is my C# solution written after the mock interview.

There are three issues to fix in order to pass online judge. First one is to check base condition, check array length is 0 on line 26; second one is to apply Array.Reverse API, it has been called three times. And the last one is to add if condition statement on line 49.

Leetcode 685: Redundant Connection II

Feb. 2, 2018

Plan to work on hard level algorithm.

Float number and operators algorithm

Feb. 2, 2018

Introduction


I asked the peer to solve the float number and operator algorithm on Feb. 1, 2018 10:00 PM mock interview. It is such a learning experience for me to learn how the peer came out the recursive solution.

Code review


The code has some issue. Subproblem should include maximum and minimum value.

The Java code is here.

Actionable Item


I will write the code based on the idea of recursive function.

Leetcode 54: Spiral matrix

Feb. 2 2018

Introduction


It is the second time I asked leetcode 54: spiral matrix in the anonymous interview as an interviewer. I met a peer who was willing to be interviewed, and followed my hint and try to write a solution using one loop instead of four for loops for each direction.

Code review


Here is Java code to review. The peer spent around 20 minutes to work on coding, I was able to see how good the peer can write readable code.

I told the peer that he did better than me. When I was asked this algorithm and the idea to write one loop only, it took me more time to come out the ideas, and I needed two hints, one for direction array, one for visited array.

Compared to the peer, I knew that I have to learn to stay open and think hard in the mock interview.




Minimum path from root node to leaf node in a tree

Feb. 2, 2018

Introduction


It is 8:00 PM mock interview. My algorithm is to calculate the minimum path sum from root node to leaf node.

Code review


Here is C# code.

Thursday, February 1, 2018

Leetcode 10: regular expression matching

February 1, 2018

Introduction


I understand that there is no hard algorithm, only lazy student. I have spent over 10 times to practice Leetcode 10: regular expression matching last eight months. Usually the peer writes a perfect solution and it takes 30 minutes, I experience a lot of good learning experience from those peers.

Last two months I start to write dynamic programming solution as well to solve the problem.

One hour practice


On January 31, 2018 I had a mock interview, and then I spent one hour to be interviewer. The peer  wrote a perfect dynamic programming solution. And the peer shared his argument that one time for b* pattern is not necessary in implementation.

Argument to think about

b* can repeat zero time, more than one time. But one time can be covered by zero time and more than one time this two cases.

Here is the transcript I reviewed.


Leetcode 394: Decode string

Feb. 1, 2018

Plan to work on the algorithm.


Leetcode 726: Number of atoms (V)

February 1, 2018

Introduction


It is hard level algorithm and I like to learn one thing a time through the practice. This practice is based on the coding blog written in Chinese, and I like to develop a blog based on the idea.

Here is the Chinese blog link.

Analysis of the algorithm


The idea is to find the first close bracket ')' and then look ahead for the number and look backward to find open bracket to match the close bracket.

Here is C++ code to study. I will write a C# solution based on C++ code.

Leetcode 726: Number of Atoms (IV)

Feb. 1, 2018

Introduction


It is very interesting to read one of discussion and the code is implemented in python. What I like to do is to spend 30 minutes to go over the analysis, and then get the idea how python code works.

What I like to do is to go over the analysis again, and write down the analysis in my own words. Spend more time on the analysis, and then understand the algorithm one thing a time.

Python code


Here is the discussion link.


Study of the blogger


Here is the link I like to study about system design.

Analysis of the algorithm


Regular expression
The first is to understand how to read regular expression, the atom can be expressed in the following expression: ([A-Z]{1}[a-z]?|\\(|\\)|\\d+). I just learned how to write regular expression in 5 minutes.  I documented my practice on algorithm on word count engine algorithm on January 25, 2018 and learn how to write regular expression for delimiters.

The number of atoms
The regular expression can be used to split the input string, and the only four tokens are discussed.  (1) An atom (2) A number (3) Open bracket (4) Closing bracket.

Let us go over a few test case and then how to read them in char array.
An input of Mg(OH)2 will be tokenized into: ['Mg', '(', 'O', 'H', ')', '2'].
An input of 
K4(ON(SO3)2)2 will be tokenized into: ['K', '4', '(', 'O', 'N', '(', 'S', 'O', '3', ')', '2', ')', '2'].

How to solve the problem?
As we iterate through the tokens, there are three cases that we need to handle:
  1. Open bracket - We push a new dictionary onto a stack to keep track of the atoms and its count in this current group.
  2. Close bracket - The next token might be a number/count. Check whether if it is a count. If it is, multiply all the atoms at the top of the stack by the count and combine it with a dictionary below it in the stack.
  3. Normal atom - The next token might be a number/count. Check whether if it is a count. If it is, add that atom and its count to the top of the stack.
Cases 2 and 3 are very similar, so we can combine them.

At the end, sort the atoms alphabetically and format them nicely to be returned.

Leetcode 726: Number of Atoms (III)

Feb. 12, 2018

Introduction


It takes at least 10 times to learn a hard algorithm on Leetcode 726. One thing I did is to study one of C# solution on discussion panel, and review the C# code and try to make it better.

Iterative solution


Here is the C# code I spent over 30 minutes to rewrite. I will continue to review the C# code. The practice is very helpful for me to understand the algorithm.