Tuesday, September 11, 2018

Math easy level algorithms

Sept. 11, 2018

Introduction


It is Tuesday evening 9:12 PM. It is time for me to write an easy level algorithm. I still have 18 easy math level algorithms to work on.

One easy level algorithm a day


It is better for me to submit at least one algorithm a day on Leetcode.com. 

728 67.0%Easy
883 65.7%Easy
868 59.5%Easy
800 55.0%Easy
892 54.8%Easy
812 53.6%Easy
258 52.6%Easy
171 49.7%Easy
13 49.4%Easy
453 48.3%Easy
598 48.0%Easy
             

C# 2000 things - Property or properties

Sept. 11, 2018

Introduction


It is time for me to work on C# programming 2000 things. I plan to search using Property and then study all items including keywords: Property or properties.

Items to study


Leetcode article - 138. Copy list with random pointer

Sept. 11, 2018

Introduction


It is such great article I came cross on Leetcode.com website. Here is the link.


Monday, September 10, 2018

Leetcode 109. Convert sorted list to binary search tree

Sept. 10, 2018

Introduction


It is my favorite tree algorithm. I had chance to work on the algorithms since I asked the algorithm in mock interview at 10:00 PM as an interviewer. I had discussion with the peer on time complexity, I asked if the solution is bottom up or top down.

In order to clear my doubt, I look up Leetcode discuss, and then I know that geeksforgeeks.com should have the correct answer. Here is the link.

My practice


I like to write C# code and practice this algorithm again.

I found this article is very well written for the optimal time complexity solution, and then I wrote a C# code based on that.

My code is here.

My favorite article 


I like to copy the analysis from the article and share here first. I like to highlight a few words for me to memorize the approach better.

Naive Solution:
A naive way is to apply the previous solution directly. In each recursive call, you would have to traverse half of the list’s length to find the middle element. The run time complexity is clearly O(N lg N), where N is the total number of elements in the list. This is because each level of recursive call requires a total of N/2 traversal steps in the list, and there are a total of lg number of levels (ie, the height of the balanced tree).
Hint:
How about inserting nodes following the list’s order? If we can achieve this, we no longer need to find the middle element, as we are able to traverse the list while inserting nodes to the tree.
Best Solution:
As usual, the best solution requires you to think from another perspective. In other words, we no longer create nodes in the tree using the top-down approach. We create nodes bottom-up, and assign them to its parents. The bottom-up approach enables us to access the list in its order while creating nodes.
Isn’t the bottom-up approach neat? Each time you are stucked with the top-down approach, give bottom-up a try. Although bottom-up approach is not the most natural way we think, it is extremely helpful in some cases. However, you should prefer top-down instead of bottom-up in general, since the latter is more difficult to verify in correctness.
Below is the code for converting a singly linked list to a balanced BST. Please note that the algorithm requires the list’s length to be passed in as the function’s parameters. The list’s length could be found in O(N) time by traversing the entire list’s once. The recursive calls traverse the list and create tree’s nodes by the list’s order, which also takes O(N) time. Therefore, the overall run time complexity is still O(N).

My argument of bottom-up approach

The idea of linear time solution is to iterate the single linked list once, and each node visited will be the root node inside inorder traversal recursive function. 

How to reason that? 

We know that binary search tree inorder traversal is to visit left child, root node and then right child. So that the inorder traversal of binary search tree will be in ascending order. Every visited node will be the root node which is visited once and only once. 

C# keywords: virtual, new, sealed, override

Sept. 10, 2018

Introduction


It is a good question when to review object oriented polymorphism in C# language. I always am super busy. But I have to find time to work on it 20 - 30 minutes a time.

I plan to study those items related to polymorphism in 2000 things you should know about C#.

One by one


Here are the list of items for me to study, review, and take some notes.

C# base class and base keyword

Sept. 10, 2018

Introduction


It is a good drill to work on C# 2000 things 20 minutes a time. A few times a month. I did search base through C# 2000 things. I did once, and then I had chance to look into over 20 items related to base class, base keyword.

One by one 


I like to go over one by one. Here are the items.

Sunday, September 9, 2018

Learn to play hard time

Sept. 9, 2018

Introduction


I like to spend 20 to 30  minutes to review the US open final Serena three code violations incident by reading some articles. Here is one of them.

I think that the drama between Serena and umpire Romas is very good case to study, and I definitely like to share this story and relate to the work place if I have time.




Object-oriented design - clean code talk

Sept. 9, 2018

Introduction


It is very good idea to review my study completed more than two years ago called clean code talk. I reviewed the blogs and then add some content in the github to get more organized.

Here is the link of github.

Here is the blog to document my study.


Leetcode Weekly Contest 101

Sept. 9, 2018

Introduction


It is the contest I played and enjoyed. I learned a few lessons. I really like to write down my experience, and then figure out ways to build good habit to play the contest every week, every Saturday, 90 minutes, from 6:30 PM to 8:00 PM.

Three good things to play contest


I learned a few things after the contest 101. I started to follow the discuss right away after the contest. The community is more active to share the code, idea, and help each other. All those players just finish the contest, I like the community.

Those players are super talent, and I do think that there are very smart and very hard working, and also very role models I can find and learn from.




902. Numbers At Most N Given Digit Set

Sept. 9, 2018

Introduction


It is the hard level algorithm. I spent over one hour to work on it in the contest, I came out the idea to work on the solution, but most of my time was to fix bugs related to the test cases.

I like to review the code I wrote and then find out the problems I had through those C# code.


My submissions in the contest


I like to document the submissions I had in the contest.

Here is the picture:


I definitely learned the algorithm and figured out the solution by those failed test cases. I did not take time to document those test cases now.

My C# code review


I like to document my C# code here. I like to review and make some comment for practice after the contest.

My code written 6:30 PM - 8:30 PM

Here is the code I wrote and updated after the contest.

Some advice:

1. Do not write lessThan or lessEqual function. Try to use SortedSet class and use getInBetween API etc.
2. Do not need to write my own API.
3. Try to think and write using existing API, specially in the contest.





Realtor study in USA

Sept. 9, 2018

Introduction


It is so nice to have friends who share the article about rental in USA on wechat. Here is the link.

More research


The idea is to copy the content on my blog first, save it on my github, and then I will research on more.

房产出租收入的所得税
外国人在美国当房东,获得的租金收入属于美国境内的收入,必须在美国缴纳所得税。对于外籍人士来讲,对租赁所得进行课税的方式由房产拥有者参与租赁经营活动的程度而定。如果只是单纯出租,即租户在支付房租外,另外自行支付房地产税、维修费用和保险费,那么房产拥有者被视为被动参与经营,这种被动租赁收入采用统一30%税率,而且税务部门需要提前扣除。被动租赁收入的30%,是指租约上房东与租户约定的租金,房东不得扣除物业费、保险费、中介费、维修费等与房屋维护相关的支出费用。
另一方面,如果外籍人士参与了日常管理、运营和维护出租房屋,那么房产拥有者就属于积极参与经营,租赁收入可以依照普通累进税率进行纳税,这时抵押贷款利率、房产税、维护费用、修理费用和折旧等费用都可以做为支出来计算所得税。外籍投资者可以选择将被动出租收入做为在美国的贸易或业务,从而按照累进税率纳税。 
在美有出租收入的外国房东,需要在每年6月15日之前应填写税务申报表格,申报给美国税务局。如果来不及准备报税材料,可以申请延期到当年10月15日。但必须要在6月15日报税截止日或之前及时递交延期申请。在递交税表时需要同时递交纳税人识别号申请表,即ITIN (Individual Taxpayer Identification Number ITIN),这是美国国税局针对非美国税务居民,但有报税义务的人士而专门设立的识别号码。没有ITIN,就无法向美国税务局报税。

房产出售的利得税
当房产出售时,出售价格与出售成本之间(包括增值成本:如装修,维修成本等)的差额即是资本利得,投资者根据房产持有时间的长短按照资本所得收益纳税。如果是短期持有,即持有房产不到一年,则资本利得按照个人所得税的税率纳税(10%-39.6%)。如果是长期持有,即一年以上,则资本利得税为0至20%(大部分按15%)。
这里需要指出的是,外籍人士在出售美国房产时,买方将按照法律规定代扣成交额的15%做为预扣税。买方代理律师必须在房产成交后的20天内将预扣税上交美国国税局,做为非税务居民的卖方(外籍人士)将会收到售房余款以及8288A 表做为今后的报税凭证。15%的预扣税并不是卖方应该缴纳的所得税,卖方可以通过税务申报来申请退回多缴的预扣税。
对于外籍买家,房屋出租收益和出售收益都是预缴税,如果真正的税款比预缴金额低,您可以在报税时将多付的税金取回,如果真正的税款高于预缴税,在报税的时候您也有责任将剩余部分补齐。 

Lu Qi - Computer scientist

Sept. 9, 2018

Introduction


It is so interesting to read the Chinese article through wechat, I learn so quickly and then I look up more through Google.com. Here is the Chinese article.

It is better to take some notes, usually the article on wechat will be expired for any reason.

My note


Let me copy some content here and then look into later.


1989年,卡耐基梅隆大学教授克拉克,到复旦交流讲学。讲学那天是周末,不巧下了一场大暴雨,所以来听讲座的学生寥寥无几。

如果按照以往的安排,陆奇周末都要回家看父母,但突然袭来的大暴雨,迫使他取消了回家计划。没有回家的他接到一个任务:“去克拉克讲座填一个空座。”

克拉克讲完课,让学生提问。陆奇接连提了几个问题,克拉克一听,大吃一 惊。于是他跑去翻阅陆奇写的论文,这一看,他更是喜欢得不得了:“你到梅隆大学留学吧。”

当时,陆奇有点犹豫,“在大学当老师已经是很不错的职业了。”但克拉克一句话打动了陆奇:“你是鹰,不应该局限在笼子里。”

在梅隆大学读博期间,陆奇发表了多篇高水准论文,迅速崛起成为计算机领域的一流科学家。

1995年,博士毕业后,在师兄李开复建议下,陆奇加入了IBM实验室,研究起网络技术来。

1998年,陆奇和同学在餐馆吃饭时,谈起了自己对互联网发展的一些猜想。正在邻桌吃饭的雅虎技术主管,听到陆奇的一番言论后,跑了过来:“你可以来一趟雅虎公司吗?”陆奇到达雅虎办公室之后,聘书已经放在了桌子上。1998年8月17日,陆奇加入雅虎,成了开发搜索引擎的工程师。
陆奇实在是太厉害了,只用了短短十年,他就从一名普通工程师升到了雅虎执行副总裁。

2007年,微软欲收购雅虎,于是展开了一系列谈判。最终,谈判失败。尽管谈判失败了,但微软CEO鲍尔默却收获了意外惊喜:“我认识了陆奇。”

当时陆奇原本已打算回国创业,但鲍尔默找到陆奇,与其长谈6个小时后,陆奇改变了想法,因为鲍尔默给了一个极其诱人的职务——微软全球执行副总裁。出任微软全球执行副总裁,这可是有史以来,华人在全球科技领域获得的最高职位。

很多人觉得陆奇是高攀了,但鲍尔默却觉得是微软赚了:“雇用陆奇的费用,跟收购雅虎比起来,我们少花了399亿美金。”


担任微软全球执行副总裁后,陆奇掌管了Office、Bing等重要产品。在陆奇的率领下,几乎从零起步的Bing搜索,竟然从强势的谷歌眼皮底下,硬生生抢到了20%多的市场份额,并通过和Facebook合作,成为对抗谷歌搜索的第一生力军。

谷歌搜索部门副总裁曼伯尔说:“陆奇是我们最厉害的竞争对手。”

不仅仅只是Bing,在陆奇率领下,“Office成为微软最赚钱的部门。”


Saturday, September 8, 2018

Math easy level algorithm training

Sept. 8, 2018

Introduction


It is hard to describe what kind of training it is to work on math easy level algorithm. I stayed at home the whole day, but I only worked on a few algorithms.

How tough it is


Let me use the submission records to show how tough it is. It is a lot of submissions and a lot of failed submissions in red colors. Here is the copy of submission record. 6:22 PM.



Algorithm design in Chinese

Sept. 8, 2018

Introduction


It is so amazing, I like the explanation of the algorithm. Here is the link.

I like to spend some time to go over those lecture notes.

It is the first time I read the website written by taiwan university.


ABC: Always be coding

Sept. 8, 2018


Introduction


It is my good research topic. ABC: Always be coding, here is the blog post link, and it is part of repository I just forked called Interviews. It is very similar to the one I have, start to work on Leetcode easy level algorithms first, or my study of total submission on Leetcode.com, over 1000 submission in the last year is a good target.

What I learn from my experience is that I will have hard time to build good habit to code every day, specially work with Leetcode online judge. I know that I have to train myself to move forward, and focus on completing more submission on Leetcode.com first, try to get more algorithms solved first.

It does not matter easy or medium or hard. Of course, it is much better to start with easy ones first.

It is much better and I will have a happy life to live as a software programmer if I set target on my training, and then I know that the reality of the world, how competitive it is and it should be. Of course we do not need to solve the problem in less than 10 minutes, but the training and preparation just makes me as a better problem solver and also a more happy person.

If I can solve tough algorithm and data structure problems, then I should do better to learn to solve daily problems, in terms of housing, living expenses, and career direction and other things.

Take my note



Awesome competitive programming

Sept. 8, 2018

Introduction


It is a small world. I sent out the congrats to the Waterloo undergraduate for his new intern position, and he replied with thanks. So I thought that he is very cool, I still remembered the chat with him over mock interview platform more than one year ago. So I did some google search and went over his starred repository on github. I found a few of them are very interesting.

This is my most favorite one called Awesome competitive programming.

I will study and put together some study notes here. Here is the link.





Developer roadmap

Sept. 8, 2018

Introduction


It is very nice repository called developer roadmap. I plan to spend time to study the content. Here is the link.




Leetcode 7. Reverse integer

Sept. 8, 2018

Introduction


It is an easy level  math algorithm. I like the algorithm and my practice is kind of easy, since I solved similar problems before a few times.


My practice


Here is the link I shared my practice on Leetcode.com.



Leetcode 507. Perfect number

Sept. 8, 2018

Introduction


It is an easy level algorithm, I did learn a few things in order to pass online judge.

My practice


Here is the link I shared my practice.


Leetcode 633. Sum of square numbers

Sept. 8, 2018

Introduction


It is an easy level math problem. I did submit 6 times until I fixed all the issues. Such a great workout. I need this kind of training.

My practice


I came out two ideas and decide to go for one of ideas. Here are my highlights of my mistakes.

1. Non-negative numbers -> should include zero;
2. 0 + 4 = 4, so given number 4, return true;
3. a * a + b * b = c, a and b can be same number;
4. given value 0, 0 + 0 = 0.
5. Last executed input: 2147483646, I put the numbers into the list and then convert it to the array.
Memory limit executed. No need to use extra space.

I like to share my practice on leetcode.com, here is the link.

Thursday, September 6, 2018

Leetcode total submission study

Sept. 6, 2018

Introduction


It is called total submissions. I like to find 10 role models on Leetcode practice website, and then I like to use this metric called total submissions to measure progress.

10 role models


1. Box Inc, Yong Su, the profile is here. Reputation 5409  - total submission: 5089
2. Facebook, Yangshun Tay, the profile is here.  Reputation 500  - total submission: 1743
3. Google, Tian Yuan, the profile is here. - total submission: 1475
4. IBM, Lee, the profile is here. Reputation is over 4000. Submission last year 1972. - total submission: 67674
5. Facebook, Yuan Tian, the profile is here. Reputation is 583. Submission last year 1161. solved 668/893. One of my favorite discuss is longest univalue path. - total submission: 3095
6. Naveen kumar, EMC, profile is here. One of his discuss is longest univalue path. he demonstrated good analysis the algorithm. - total submission: 1951
7. Shan Gao, Google, profile is here. Reputation is 4636. He demonstrated good proof in the algorithm called Array Partition I. Here is the sharing. - total submission: 3646
8. Microsoft, profile is here.  - total submission: 4134
9. Stefan Pochmann, over 20,000 reputation. The profile is here. - total submission: 14530


More submissions


I was so surprised that my submission is 710. I have 292 submissions in the last year.

Jianmin Chen, 9 reputation. The profile is here. - total submission: 710


My analysis based on the study


Those role models hold full time software programmer jobs, but they still find time to make thousand submission in the last years. They work for top software companies, like Google, Microsoft, Facebook, IBM. 

My argument is that I have to find excuses for myself lack of enough submissions. One thing I like to say is that I need coach's advice. Find right thing to do first. 

Second one is how to do it. My coach gave me the advice in July 10, 2018. Work on easy level algorithms first. 

I was thinking about designing drills for hard level algorithms, and evaluated myself to be good with easy and medium level algorithms. I did some campaign and wrote down my thought process through the blog. 


Leetcode 400. Nth Digit

Sept. 8, 2018

Introduction


It is not surprising for me to read the discuss and find an easy and very short solution. I spent over hours to work on the code with 6 failed submissions. It is so friendly remind for me to stay humble, and work hard to play against integer out-of-range issue. I also love to learn how to solve the problem first.

Mathematics is my favorite subject, I spent over 5 years to study math course, and it is time for me to get some experience to code on math algorithm problems.

My practice


I studied one of discuss and wrote the same idea. Here is the code I shared on Leetcode.com.


Leetcode 400. Nth Digit - 6 failed submissions

Sept. 6, 2018

Introduction


It is the first easy level math algorithm I worked on. I chose Nth digit. I just could not believe that I came out the steps to work on, but my coding skills and also test skills did not catch up. I lost control of time and bugs were difficult to identify.

My practice with struggle 


Here is my first C# submission.

Failed test case:
input: 10
output: 0
expected: 1



Six failed submissions



It is such a battle against the following errors:

First submission, 27/70 test cases passed, failed test case:
input:10
output:0
Expected: 1

24/70 test cases passed, failed test case:
input: 11
output: 1
expected: 0

42/70 test cases passed, failed test case:
input: 100
output: 1
expected: 5

43/70 test cases passed, failed test case:
input: 1000
output: 4
expected: 3

Runtime Error
Unhandled Exception:
IndexoutofrangeException
getDigitInInteger

Wrong answer
43/70 test cases passed, failed test case:

Input: 1000
Output: 4
Expected: 3

Here is 6th failed submission - C# code. Here is the link I shared on discuss panel. 

I will write the working one based on the same idea. It is hard to write, I need to handle int out-of-range issue. It is best practice to learn how to handle integer out of range issue. 





If I were an Amazon recruiter

If I am a Google recruiter

If I were a Facebook recruiter

If I were a Microsoft recruiter

Sept. 6, 2018

Introduction


I came out the idea to write the blog using this topic "If I were a Microsoft recruiter". I had the idea after I did three hours study on Leetcode contest 99, I was so amazed that people are working so hard to practice on Leetcode.com and also share their passion and knowledge, and I was so surprised that I can use those Leetcode.com data to analyze a player's performance and potential, even the work ethnics.

I know that it is so difficult for me to make decision who to contact if I were a Microsoft recruiter, and I did some study on those player's performance on Leetcode contest.

Official blog about Microsoft 


I am the recruiter, so I will study more from Microsoft official site about what they are looking for. Here is the article called "I'm Microsoft' Head of Talent: Here's How to Get Hired".

My own research to identify talent


I certainly can do my own research, for example, using Leetcode contest 99, and then find a candidate hired by Microsoft before, using his data, evaluate the talent.

I like to explore Leetcode contest, and find top 10% on the market in terms of data structure and algorithm. So I can use this data for me to come out the formula to evaluate the potential candidate if Leetcode data is available for the candidate. The comparison is best way.




Rough estimation how competitive I am using Leetcode data

Sept. 6, 2018

Introduction


It is my research of 20 - 30 minutes. Now it is 12:14 AM. I need to finish up the work and go to sleep. I spent over three hours to study Leetcode role models and contest 99. Now it is time for me to estimate how competitive I can be compared to those top 400 players in Leetcode contest 99.


Relax and get into measurement


It is not so optimistic compared to those young graduate students, young professionals.

Follow up 


Sept. 16, 2018 5:41 PM

Very competitive programmer can finish Leetcode 300 algorithms in 3 - 4 months. How long can I complete the task? Compare my time to those people with 3 - 4 months, what can I do to expedite my process?





Leetcode contest 99 study

Sept. 6, 2018

Introduction


It is the first time I spent over two hours to study Leetcode 99 contest. I spent time to go over the players with score 14, ranking after 400.

Players 

I like to find some players as role models. And then I decided to look into one of contests, and see who are those players.

Now it is 10:42 PM. I like to find very good role model to demonstrate good skills in reasoning and competitive skills in contests.

lixx2100

I did look at contest winner, here is the discussion I like to read. The user's profile is here, who works for Facebook. Reputation is 1581. The contest winning page is here.

Bowen Yu - ICPC coach, NYU ph.d.

http://bowenyu.me/interests.html

Microsoft
https://leetcode.com/leoncheng/

Cui Aoxiao
Youtube video about contest.

Google search: leetcode cuiaoxiang
Here is my favorite discussion about contest. Contest 87, here is the discuss.

Microsoft
Profile is here. High ranking in contest. Ranking no. 2 of contest 99. Here is the link. Here is the linkedin.

Anonymous

Hardworking Googler - solved over 800 algorithms. Here is the profile.


Actionable Items


Another young graduate student works very hard, solve over 800 algorithms on Leetcode.com. And also the player also plays contests. Then the player gets the job from Google. Here is the profile.

I did look up contest 99 top 500 players. Here is the link. I need to come out the idea of a few factors: positions, years of experience, solved algorithm, contest performance, submissions last year, and then comparison to the young graduate, new Googler.

Here is one player I studied, rank 410 of contest 99.

I spent time from 9:03 PM to 11:48 PM. I think that it will help me work hard on Leetcode and get more understanding about the community.

Wednesday, September 5, 2018

10 role models on Leetcode submissions

Sept. 5, 2018

Introduction


It is my short research to find 10 role models on Leetcode.com. I like to study how often they submit the solution, what algorithm they work on, what language they use, and also how many submissions for one algorithm, total submissions.

10 role models


I like to list 10 role models, so I can start to look into and figure out something.

1. Box Inc, Yong Su, the profile is here. Reputation 5409
2. Facebook, Yangshun Tay, the profile is here.  Reputation 500
3. Google, Tian Yuan, the profile is here.
4. IBM, Lee, the profile is here. Reputation is over 4000. Submission last year 1972.
5. Microsoft, Alexander, the profile is here. Reputation is 1559. Submission last year 1872.
6. Facebook, Yuan Tian, the profile is here. Reputation is 583. Submission last year 1161. solved 668/893. One of my favorite discuss is longest univalue path.
7. Naveen kumar, EMC, profile is here. One of his discuss is longest univalue path. he demonstrated good analysis the algorithm.
8. Shan Gao, Google, profile is here. Reputation is 4636. He demonstrated good proof in the algorithm called Array Partition I. Here is the sharing.
9. Microsoft, profile is here.
10. Stefan Pochmann, over 20,000 reputation. The profile is here.

I like this post on quora.com by one of Leetcode founders. Please take a look those three players: dietpepsi, yavinci, j.e.fighter