Showing posts with label code review. Show all posts
Showing posts with label code review. Show all posts

Monday, April 30, 2018

Code review: Array quadruplet

April 30, 2018

Introduction


It is so happy for me to continue to practice Array quadruplet algorithm since last March. What I have learned through over 10 rounds mock interview is that I have to continue to learn the algorithm through each practice.

It is the big surprise when I chose the algorithm to ask the peer last Saturday 10:00 PM mock interview. I tried to test a senior in the university how good he is since he told me that he had ICPC contest experience in high school.

Build a hashmap on the fly


I like to answer my own question asked five months ago on stackexchange.com. Here is the question's link. Here is my answer's link.

Leetcode 4 sum discussion panel


I have to push myself to learn from others. One drill is to read as many discussion as possible, and try to figure out new ideas, creative thinking process. I spent 30 minutes to read through the discussion, and also wrote a reply. Here is my reply link.

I noticed that I had some issues, since I keep checking code review my answer link. I know that it is waste of my time. I should spend time to read more discussion on Leetcode 4 sum.

Sometimes I notice that I have to push myself to show concern to others, people in the community, and also give out support for other people's good thoughts and work they share.

To be selfish or pessimistic, it is not working very well in this fast-paced software industry. This is the first time I make this argument.


Here is my post to show my idea and answer for Leetcode 18: 4 sum. I did spend 30 minutes to read my submission eleven months ago and then I decided to write a new solution based on my practice on array quadruplet.

One step further


Here is the reply I gave to the most view answer 6.1 K views. I shared the tip to lower down the time complexity to O(n * n).




Monday, March 26, 2018

Being an interviewer: Leetcode 250: Count univalue subtrees

March 26, 2018

Introduction


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

Code review


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

I will document my code review here as well.


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

Here is my code review:

isUnivalTree function


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




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



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


checkSize function


There are a few issues on checkSize API,



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

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

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

  Here is the code I think with better presentation:


Clean up is a small good thing to do


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

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

Wednesday, March 14, 2018

Object-oriented design review

March 14, 2018

Introduction


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

Code review


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

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

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


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

So here is the discussion panel.

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

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

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

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

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



Saturday, December 23, 2017

Code review: At least 2 paths down the binary tree have the same sum

Dec. 23, 2017

Introduction


It is my most favorite algorithm in the world in June 2016. I had to go through the transition to accept myself as a software programmer, and learn how to improve myself through this simple algorithm. I did the practice and then stopped without writing an optimal solution in June 2016. Now after more than 12 months, I know that at the time I do not have high standards on practice at all.

Here is the algorithm I practice in June 2016.

I reviewed the code on Dec. 23, 2017 and asked the question on code review website. Here is the code review web link.

June 2016


It is tough to deal with frustration, what I did is to write a blog to study the failure on June 5, 2016. I was so excited to go over one day meeting with the most highest standard software company. And then I experienced so many issues through meetings. One thing is that I did not perform very well on the similar algorithm using C# LINQ.

Add one more paragraph


One thing I like to do is to add one more paragraph on the code review. Since I do not get any upvote after 24 hours, so I like to step out and do something to help myself.

Here is the paragraph:

Code improvements
I decided to make a few improvements based on my last practice over 18 months ago. Internal class is used instead of external class. I choose to use camel case for public method, and rename the function DuplicateCheckingPathSum to make the function name self-documenting. Specially I took 10 - 20 minutes to go over those stackoverflow links to learn LINQ and also ASP.NET C# class and I found that those links are really helpful for me to warm up LINQ. It is tough for me to see that after 18 months I still do not make big progress on LINQ and the functional programming syntax still looks like foreigners to me.
Most of important change is that I learn better recursive function design after 18 months. I was surprised that I ended my last practice with so many issues. The base case should be selected to avoid duplicated count of each path. I like to see the depth first search algorithm specially a recursive function is written in very structured way, base case is very clear and also the recurrence formula afterwards.

Follow up 



Dec. 25, 2017
Early in the morning I got code review, and I was so excited to read the review. Here is the link of code review.



Tuesday, December 5, 2017

Leetcode 37: Sudoku Solver

Dec. 5, 2017

Introduction


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

Here is C# code.


Dec. 6, 2017

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

Static vs Const


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

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

public static readonly int SIZE = 8; 

or

public const int SIZE = 8; 


SIZE or LASTCOLUMN


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

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

better saying
board.GetLength(0) <= LASTCOLUMN


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

Line 5: public static int LASTCOLUMN = 8.

Actionable Items


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

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

Plan to read 10 minutes on this discussion:

Argument or facts:


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

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

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

Monday, November 6, 2017

Code Review: Sudoku solver recursive solution with clear structure

Nov. 6, 2017

Introduction


It only takes less than one hour to post the question on code review. The algorithm is Leetcode 37: Sudoku solver, the most classical depth first search algorithm. My practice is documented here.

It is a wise decision to ask a question on code review website, this time I learn a few things from code review.


Code Review


Code review link is here.

I got very good review. My most favorite advice is Code to interface. Use IEnumrable<char> instead of using HashSet<char>.

Thursday, September 28, 2017

Thanksgiving campaign No. 1

Sept. 28, 2017

Introduction


I plan to do some campaign for Canada thanksgiving holiday, to express my great holiday spirit. First activity is to ask a question on code review website. I miss those people who helped me from Nov. 2016 to March 2017, I like to go back to be one member of community.

It is so nice to experience the code review again tonight. I just posted the algorithm in less than 10 minutes ago around 10:30 PM, the best programmer already edited my post to fix style issues, grammar errors, clarify the problem statement by going over the content. The user profile is 200 Success, who is the moderator.

I miss the people to review my code, help me to become a better competitive programmer starting from Nov. 2016. After 6 months break, I finally decide to go back to routine to ask questions on code review website.


Thanksgiving activities


This past year is the tough for me physically, first time in my life I feel the uncomfortable on my right knee. I experience some short memory loss compared to strong memory before, for instance, I forget a friend's name if I have not met him last 6 months. I feel different specially I have to handle a deep pocket of my big tooth left side jaw, and I feel that aging is a university and I have to work hard to catch up learning how to deal with those new challenges.

I like to ask myself what I should do to stay connected to those people helping me grow as a software programmer. Those people help me, touch my heart to make my algorithm practice so interesting and also so rewarding. One of them is JS1 who shared the great advice for my coding solution.

Here is the snapshot to show how good the work is, I learn to improve my English writing so efficiently:


Here is my code review algorithm Find the smallest substring that contains some given subset of characters. Twitter link is here. 

Follow up


Oct. 25, 2017

code review C# code is here.

Sunday, April 30, 2017

Talent small talk

April 30, 2017

Introduction 


It is a very happy weekend with a world codesprint contest and then two mocking experience. Julia also spent one hour to play some tennis and felt much better after she ran 30 - 45 minutes, she was amazed that her muscle memory of tennis was so good, she could control tennis balls so well through a full court rally. She enjoyed the sliced shot and very good timing and control of landing position to hit a stroke.

She also felt that it is important to seek the advice to be a just-so-so contest player scoring 36 points over 13 hours compared to top players scoring more than 280 in less than 2 hours. Read those data - less than one hours 10 minutes, top number 1 - Gennady.




What are the missing parts she should work on next?

A lot of professional WTA tennis players are very good at changing coaches when they deal with up-and-downs. What does Julia do for this case? Should she change her coach? She is self-coaching and writing blogs to keep tracking of her progress.

Need a therapy after the contest. Remember the favorite video she watched about Roger Federal talking about his early age, throwing tennis racquet in front of thousands fans. Take some time to learn from Roger Federer.

Watch this video to get entertained. Roger Federer - top 10 smiling after points lost, link is here.

Talent talk 


Where is the talent? I like to find some drills to work on to help myself to cover the weakness of talent. 

Watch the video - tennis funniest moments ever. Link is here. And read the article - waste time is healthy in big data term, link is here

Data structure talk 



Julia met a same person for the second time in less than 30 days through mocking experience, and then she learned a few things through 30 minutes. Friendship forms quickly after the first experience.

Case 1: She likes to design a data structure to return a list of pair integer numbers in the array, she said that since it is the unknown size, she likes to declare C# IList<string>, and then "why it is string?" The peer asked, Julia said that because there are two numbers, I like to encode and decode like a + b; otherwise I like to use Tuple<int, int>, the peer just typed that you just use this one IList<int[]>.

Julia never uses this one before, but it is so good ride once she uses it. Story is short, better give a good name "int[] beats string".

Case 2: Julia likes to change HashSet to a Dictionary<int, Object>, and then the peer asked, can you make a minor change to fit the requirement; Julia was told to finish the coding, and do a whiteboard testing using a test case. Do mocking algorithm really need Dictionary that complicated?

Through the discussion, Julia learned that it is a good practice to write simple code. Be more organized!

Transcript is here. Later it will be compiled to C# code.

Recurrence formula talk 



It comes out that the recurrence formula is challenging for those 3  talented programmers in the world last weekend. In other words, Julia used the same algorithm to interview two people last weekend.

Her first interviewee was troubled, confused, since the problem statement is wrong, and Julia had difficult time to step in and give good hints to guide, since Julia had a math degree but it is like the muscle to fat story, she also got confused on recurrence formula in those 30 minutes. But then second time to use the algorithm, Julia was more determined to apply recurrence formula, no more playing with test cases. Just write down clearly the formula first.

The interviewee is much quickly to take hint, and then write code. She felt those two difference. Less experienced one is much more easy to try new things.


Also Julia learned the algorithm quickly, when she interviewed second person using same algorithm, she wants to make the difference. She learned that good interviewer should do something to help out. 

Whiteboard technique



From the contest to the leaderboard by Microsoft to a blog writer -

Google intern and interview blog is here. Whiteboard talk is excellent.

Bronze medal talk



It is the time to celebrate Julia’s fifth bronze medal, Julia got a bronze medal for world codesprint 10. How to express the feeling of bronze medal? Julia likes the hard work she put in those hours, and she did so much work and tried again and again for new ideas to break through the hurdles. She is more experienced to play contests now compared to last year.

Julia takes time to enjoy her status right now, one day she will easily make over 30% or over 100 points and come back to look at the stage she is in. Honestly the contest is like school home work, and bronze medal is for Julia to celebrate a grade “C”, but she tries to get grade B – silver medal, one day she can get grade A. Julia scored 36 point (360 maximum points), 10% scoring. 


Julia likes the competition because it is fair, open and her peers are all over the world. Compared to take algorithm course in university to learn more, she does not need to figure out who is the professor in the university, fair or not fair on grading. All she has to do in the competition is to work damn hard, write down something, either a blog, or code or analysis. Dedicate a few hours on each algorithm in the contest. From there she can continue to work on after the contest. 

Psalm 126:5 Those who sow with tears will reap with songs of joy.
6 Those who go out weeping, carrying seed to sow, will return with songs of joy, carrying sheaves with them.

Julia sowed, teared, reaped, sung, weeped, carried.

Follow up on data structure talk 


In previous data structure talk, Julia shared the story about mocking experience. The peer coached her to use int[] instead of using string or Tuple<int, int>. Such a wonderful coaching through mocking experience.

Afterwards, Julia asked her favorite algorithm coach JS1 on code review about using int[] data type compared to string related to Queue. Here is the algorithm question on code review. 

do you think that it is also good idea to declare var queue = new queue<int[]>? row and col can put into the array new int[2]. Therefore, we do not need to encode a key and then decode the key to row and col two variables. I am learning data structure and try to speed up coding. – Jianmin Chen

It's a matter of preference. I tend to use primitive types whenever possible, but if using int[] seems easier to understand than using a single int, then you should do that. Note that using a single encoded int leads to a simpler visited array as well. – JS1 

Saturday, April 29, 2017

Maximum Disjoint Subtree Product - World codesprint 10

April 29, 2017

Introduction


It is a wise decision to spend time for each algorithm in the contest. Even Julia did not make any points last few hours, she found out that it is better to write a brute force solution even scoring 0, or write a blog about the algorithm.

The maximum disjoint subtree product algorithm should be a DFS/ BFS tree problem. Julia had some idea to solve the problem, but she was not sure how simple the code should be.

The problem statement is here. Just work on the most simple test case, and then write some code first.

Plan to do 60 minutes workout on the algorithm. 3:03pm - 4:03pm.

Code preparation 


Read one of players resume, and go over all the players in united states scoring 60 on the algorithm. 3:13 pm, study those players and get myself ready to think about a solution and start to write down some code. 

4:00pm now - spent 20 minutes to go over those 24 people scoring 60 maximum points, and I knew that those are very experienced ones, Julia spent time to loo at those who scored 3 points, 6 points, to 30 points. Those are players who are working hard as well.

Go back to study on topcoder webpage after googling disjoint set, make the algorithm general. How to approach? Article is here

Finished 15 minutes to read the disjoint set article first. Time is checked, 4:15pm.

Disjoint-set Data structure - topcoder tutorial


Read the article - link is here, and take some notes. 

Disjoint sets, dynamic disjoint sets,
Define two sets are disjoint - intersection is null
representative - Every disjoint set contains a representative

It is assumed that the representative of each group is the person with the biggest index in the article.
Every one has its own group
-> the group containing 1 and the group with 2 will become one group.
-> the representative of first group will become 2.

How to check if two persons are in the same group? Check the representative.

Define some operations:
Create-Set
Merge-Set
Find-set

Implementation with linked lists

Each element will be in a linked list and will contain to the next element in the set and another point to the representative of the set.

Read the graph representing the problem, catch up more later.

Read how to implement the Merge-Set(x,y) operations.

a weighted-union heuristic - complexity O(M + NlogN)
where M is the number of operations (Find-sets, Merge-sets, Create-sets), N is the number of operations Create-Sets.

Two heuristics -

Union by rank
Path compression

Time is checked again, 4:53pm.

Move on to next topic

Disjoint Set questions on Hackerrank


Link is here.

Disjoint Set tutorial on hackerearth 


The article link is here.

Being a hacker 


Wrote a brute force solution to work out on sample test case, but the code passed test case 1, failed 2, 3, and time out everywhere. Score 0. Time checked, 10:53pm.



Can hackerrank give me 0.001 points? I just need 0.0001 points.

Is that possible to give 0.25 points for passing test case 1? I wrote a brute force solution just to try to advance my ranking. My points are 36 points, ranking from 767 - 1307 all scoring 36 points. Never work so hard to advance 0.25 point, failed this time.
Here is the comment link. 


Follow up 



Code written in the contest is here

Study one of C# submission code. C# study code is here with sample test case. 
Continue to code review the algorithm, prepare to give a code review on stackexchange.com, here is the C# code. 

Sunday, April 2, 2017

Code practice: analysis of scan document

April 2, 2017

Introduction


Julia likes to practice using LINQ and also learn how to write a C# program. Scan a string and then parse string using delimiters and order by descending order of word's count.

Time complexity analysis: O(Nm), N is the string length, m is the delimiters' length.

Code study 


C# code is here.

Julia reinvented the wheel, write a string.Split(char[]) method. She enjoyed the practice.

Julia need to train herself on LINQ - write statement to query Dictionary and then sort by value using descending order.

Stackoverflow question on LINQ - query dictionary and then sort by value using descending order.

Edge case in SplitMethod()

Actionable Item


Do not stop coding review. Always Julia gets surprising result. Code review this one to celebrate the weekend of first April, 2017.


Sunday, March 19, 2017

code review: Hackerrank kindergarten adventures

March 19, 2017

Problem statement

Code review is posted here.

C# code - still work on more test cases on API testing, Modify and Query.

Introduction


Julia starts to learn binary index tree and segment tree through hackerrank university codesprint #2 in November 2016, she tried a few times but failed each time. She knew that she is better to work on the algorithm "kintergarden adventure" and learn from the algorithm.

She also did post the question on segment tree algorithm on code review to ask help on Dec. 10, 2016, and then the question "kintergarden adventure" was closed. Through the incident, Julia knew that she was afraid to learn by herself.

Julia is very comfortable at data analysis, so in order to figure out the algorithm, Julia chose to have some test case study, put together some data, and then taught herself what to look for through those tables.

Test case study


For example, there are 20000 students in the circle, and the first student only need to 0 minute to finish drawing, so that if the teacher starts from any students from ID = 1 to 20000, the first student can complete the drawing. SegmentTree class Modify API has to take the task to mark those 20000 nodes as value 1, it is not scalable for 3 seconds time limit, so that we can use up to logN intervals to cover the range of [1, 20000].

To make it simple, we assume that the range's width is 1024 instead of 20000, and see how many steps we need to mark in tree[]. Not up to 1024, but in the level of logN = log1024 = 10.


Here is the SegmentTree class Modify API: To understand the test case, in order to modify 1024 nodes as 1, we only do it in less and equal to 10 times, here is the two images to explain the detail.

The two variables of left and right are iterated from beginning to end 10 times, each iteration two variables's values are recorded in the table.

Let us get our hands dirty on this test case, RunTestcaseModify3() line 12, tree.Modify(0,1024,1). We look into the function call.

First row of table, left = 20001, right = 21024, since Modify API is called and function arguments: start = 0, count = 1024, value = 1,
read Modify API code line 5 and line 6, left is calculated as 20001 and right is calculated as 21024.


and more detail is here:

Action items


Review code review Hackerrank Modular Range Queries
Read the tutorial of segment tree.
Learn binary index tree from topcoder

Inspiration


This is the first time Julia started to use Microsoft Excel to do some test case analysis to help her understand the segment tree algorithm design.

All it takes is for her to have some patience. She read those two tables built by Microsoft Excel, and then she asks herself what is missing, what problems she can tell from those data. After a few times search, she comes out ideas to move forward her study.






Friday, March 17, 2017

Code review: Longest common substring

March 17, 2017

Think about how to review previous practices on this algorithm, longest common substring.

Study suggestion:


Leetcode 340: longest substring with at most k distinct characters, read this implementation.

Leetcode 271: encode/ decode  - advice from top player.

geek for geek: Find k closest elements to a given value




Monday, March 13, 2017

Quick Search - Julia's first answer on code review

March 13, 2017

Julia got a big surprise today, her first day work on code review to answer a question on quick search was selected as the answer today, after more than 3 months, she noticed that she got 25 reputation.

The code review link is here. She has to celebrate a little bit, it was a long time she tried to find some activities to help others while she is struggling to invent herself, keep up with others in this computer science technology world.

Julia searched her blog using quicksort, and then she found somethings to review related to quicksort.

Make it more memorable, Julia uses an image and music to celebrate her good working spirit.


Jessica Simpson - Take my breath away

When  Julia read this news, she was so excited, take my breath away, a little exaggerated, reminded her a song - the old lovely song, feels good to help others and make her own mark. One step a time, ...

Actionable Items


1. Read all algorithms in the blog, the blogger got Google and Linkedin offer. The algorithms may be a good study material for Julia.

2. Review the C# implementation of quicksort, write a new one.


Thursday, February 23, 2017

code review - Hackerrank stone division

Feb 23, 2017

Introduction

Julia always chooses a topic to study, today her topic is about Google recruiting.

She came cross the article on Hackernews about Google interview, and she likes to put some number together to help her analyze the situation: (hypothetical skills)

Recruiter goes over millions resume, and start from 2000 people, try to fill 3 positions:

1: 2000 for 3 positions 

resume screen - 100,000 resume -> 2000 resume
phone screen   - 2000 people, each 30 minutes 
code screen     - ?
phone screen   - ?
in-person interview - 1 in 10 or 1 in 20 from that point
hire


and then read the comment from an ex-googler 1825 days ago, probably in 2011: 

With all that said, I haven't found any degree (at least from any school I've interviewed applicants for) to be a reliable signal for programming. Even if they went to a really good school, there's a good chance that they spent all their time learning network protocols and low-level mechanisms, and will happily write up a sliding-window implementation for me, but will stare at me blankly when I ask for a simple recursive algorithm. It's just tough to find people that spent time studying and practicing general-purpose computer science.

An googler's comment on onsite interview more than 5 years ago, Julia is the first time to get the idea:
"So what you are saying is that for me to not have made it through I must have equally messed all my interviews or at least a majority of them. I surely didn't feel like that after the interview, but who knows, since I still don't have a way to know if that is the case. Then this really sucks."
Just a comment from another Google engineer who does interviews (and didn't do yours, since I haven't done any for a couple months now): your own feeling at the end of an interview may not at all reflect your actual performance in the interview, because you have no visibility into what questions weren't asked.
I like to interview candidates by asking them to solve a simple programming problem and then modifying the specification little by little, having them adjust their solution to implement new functionality. There are about 8 steps in my question, and frequently I'm gauging the quality of the candidate by how long it takes him to get through the first N stages; we fix bugs in earlier stages before moving on to the next stage. To calibrate myself, I've tried this question on several of my coworkers, and they were universally able to get about halfway through the question with bug-free code in about 10 minutes. Only one required prompting on my part to fix a bug. Most every candidate I've interviewed has taken 20-30 minutes to get to the same halfway point; by that time I've only got 15-25 minutes left in my interview, and the candidate seems so far like a "no hire", so I move to a different question to find out if the candidate has other strengths to counterbalance his weakness at solving this (simple) coding problem.
From the candidate's perspective, he only sees me ask a series of programming questions which he answers satisfactorily with a little prompting from me. If he answers another question or two satisfactorily, he may think he's done well, but he doesn't know that I wanted to delve more deeply into every question I asked him, and just didn't have time because the pace of his solutions was too slow.
I wish I could give this feedback to the people I've interviewed, but sadly, I can't.

So, Julia searched her blog using keyword: recursive function, and then she read the first blog through the search results, and the blog is about the fact that she failed to deliver recursive function design, code in Nov 24, 2016, after so many years Ph.D. study and 7 years full time work in the city of Vancouver, and then she did some research to catch up. 

More detail, she worked on stone division more than a few hours in the contest - hackerrank woman codesprint, a medium level algorithm, maximum score 50, Julia overcooked the solution, had weak muscle on recursive thinking, and out-of-her-control, scored 0. The algorithm is called stone division.  

Here are five blogs about stone divisions, documented her experience in the hackerrank woman codesprint, series from 1 to 5, failed to score any thing from a medium level algorithm, maximum score 50, over a few hours (5 hours?) in the contest in Nov. 24, 2016, and then she took action to do some research on recursive function, and then she found code review on stackexchange.com. As a matter of fact, she got used to isolate herself so long, and in order to improve hackerrank contest performance, she seeks the change. From a lone coder, work ass off, she barely stays afloat (not in financially), so she decided to find her new schools one by one, the 3 months old new school is called codereview.stackexchange.com, she found the site just after the Nov. 2016 woman codesprint contest. 

So, she spent one hour to review the algorithm, wrote a more readable C# version this time, with 3 months experience with the code review school, with top-rated teachers from JavaScript, C#, algorithm help her to code review her code line by line, debate on basics - hash function, coding style, API design, and numerous rich experience. 

Code reivew

C# code for stone division is ready to be posted to stackexchange.com for a review. And code review link is here



Thursday, February 16, 2017

Leetcode 317: Shortest distance from all buildings (Part 4)

Feb. 16, 2017

Introduction

Julia was trying to find a good one to ask code review on stackexchange.com, and the she noticed that her blog is coming to a landmark 100,000 views. So, she likes to celebrate her hard work, she saw one of visitor was from search result using keyword: Leetcode 317 in last 7 days. So, the user of the blog solved her problem - find a nice algorithm to review. She worked on the algorithm before, she did twice. 

Her first practice is more than 12 months, she reviewed the blog in January 2016In May 11, 2016, she practised again the algorithm. Her practice code is here. Through her practice, she likes to track her progress. She likes to say just so so, coding is like tennis sport, she has to learn from best - Roger Federer.

Workout

Julia likes to rewrite the C# code based on last practice in January, 2016. And here are the highlights of change.

To challenge herself, she designed several classes to track intermediate result, for example, empty land and building distance, building key and empty land position should also be recorded, so she can test the API first.

Because there is no concern about timeout or space limitation, Julia likes to design a few APIs, and also learn how to write code to follow S.O.L.I.D. principles.

In C# code, function WalkFromBuildingBFS is set as public API, and also a test case is added. Make sure that BFS search algorithm is working fine.

Here is the C# practice ready for review. Here is the code review link

Read some posts about SOLID principles on stackoverflow.com first.

Feb. 17, 2017 10:15pm 
Read the post about SOLID principles, the link is here.

Feb. 18, 2017 11:05am 
1. Update the question of Leetcode 317 to make it more instructional - the breadth first search, including some research I did on community challenge. 

2. Study the community challenge question code review, Rainfall challenge.
     Study Java code implementation first, and then write a C# one to ask for review.


Feb. 20, 2017
Read leetcode solution discussion, one of discussion is to expedite the search, great idea I read first time:
I also tested the other three C++ solutions posted so far, they took 340-1812 ms. I think mine is faster because I don't use a fresh "visited" for each BFS. Instead, I walk only onto the cells that were reachable from all previous buildings. From the first building I only walk onto cells where grid is 0, and make them -1. From the second building I only walk onto cells where grid is -1, and I make them -2. And so on.



Sunday, February 12, 2017

Hackerrank RookieRank 2 - prefix neigbhors (II)

Feb. 12, 2017


After the contest, Julia likes to study a few of solutions in C#, Java and other languages.

Code study of submissions


C# code

C# code.

Have some difficulty to understand the algorithm behind Index.Add method. Need to figure out later. Add some test cases to C# code, debug and understand the code one line by one line.

Study a few things about C# coding style, pascal case, set, get, and then using GroupBy, OrderBy, Aggregate, Stack, HashSet, Dictionary.

Second Study 

C# code study II
C# code is here

Third Study 


Java implementation

Problems

The most readable code is here with trie implementation. Julia chose one solution from near 100 solutions, this one is easy to follow. Will rewrite the C# solution based on this Java implementation.

Actionable Items



1. Instead of studying other people's code, Julia decided to look into test case 11 and figured out why her submission failed the test case. 

2. Read editorial notes from hackerrank, understand the idea, google search them:

This problem can be solved using Trie and DP. Create a trie from the given set of strings. Find the prefix neighbor of each string. Now create a graph such that each string is a node and there exist a bidirectional edge between two nodes only if they are prefix neighbors. Now find the maximum weighted independent set.

Statistics
Difficulty: Medium
Time Complexity:

O(N*max_length_of_string)
Required Knowledge: Trie
Publish Date: Mar 25 2016


Read the wiki article - Independent set ( graph theory)
GeeksforGeek problem - Largest independent set problem

3. Julia did not know the importance of problem solving in the contest and after the contest from Feb. 11 - 13, 2017. She tried to understand the other people's submission after the contest, and she had difficult time. She needs to understand the algorithm first, just follows the notes: find the maximum weighted independent set

4. Spent over 2 hours to rewrite the C# code, and post
 a question on stackexchange.com.  

Problem solving - community help


Feb. 25, 2017 5:27pm

With the help from Peter Taylor through his code view, Julia learned so much about the problem solving skills. She answered code reviews one by one, and then felt so comfortable with the algorithm problem solving. The code review experience is top-rated performance. 

Share some comments here:

Advice #6, KISS, why? what is wrong to insert them all into one trie? This is a good question. I tried to use the above code, but use one trie instead of going through A to Z one by one, run the code on hackerrank, error from test case 6 to 19; And then, I tried not to sort by the length of string, error from test case 6 to 19. – Jianmin Chen Feb 15 at 5:06   

Very good review, I did spend over a few hours in the contest and also a few hours after the contest. I like the last review "KISS, why?" most, remind me 5 whys for root cause analysis. Bravo! – Jianmin Chen Feb 15 at 5:11