Sunday, May 5, 2019

1038. Binary Search Tree to Greater Sum Tree

I wrote a post to share on Leetcode.com discuss. Here is the link. I also like to copy and paste here in case one day the algorithm is set to the private and the discussion post is no longer available.

It is a medium level tree algorithm. I worked on the algorithm in weekly contest, I was nervous. Two mistakes dragged down my performance. It should take me 10 minutes, but I actually spent over 50 minutes, last two minutes I finally made it work in the contest.
Two most common mistakes
Let me introduce the first mistake I had, and I had to take time to figure out. I like to traversal the tree using Right, Root, Left so that all numbers will be decending order.
image
From the above diagram, a, b, c, d and e are used to mark the order of all elements in the tree. I was confused that d and e two nodes, which one should go first. I was not sure. It took me extra five minutes at least
Let me introduce my second mistake, calculate the sum of visited nodes in the tree.
image
private static void traversalRightRootLeft(TreeNode root)
        {
            if(root.right != null)
            {
                traversalRightRootLeft(root.right);
            }

            // visit root
            
            var firstCheck = previous != null  ;            
            
            if(firstCheck)
                root.val += previous.val;
                
            previous = root; 
            

            if(root.left != null)
            {
                traversalRightRootLeft(root.left);
               root.left.val += root.val; // this is a second bug
            }
        }
The second bug is to write code in the left child; The simple reasoning can pinpoint the code is wrong. Every node will be visited once, how come the node which is left child will be counted twice in calculation of node's value?
I like to explain this common mistake in recursive function so that it is much easy to understand the reasoning.
image
Advice on weekly contest
Based on the above facts, I should focus on reasoning, not just try to pass all test cases in problem solving; It is hard for me to work on something new in the contest, I was nervous but I learned two lessons from the above two mistakes in the contest.
I like to write down and share with others. We all know that practice makes perfect. What I like to do is to talk about mistake, and try to work on my reasoning skills in the contest. That will help me to improve my performance. Between 50 minutes to solve and 10 minutes to solve are huge difference in 90 minues contest.
References:
  1. weekly contest 135 website is here.
  2. My weekly performance 135 diagram with time spent on the second algorithm 54 minutes.
    image
  3. Top 10 players and their time spent on the algorithm.
image
The minimum time is 1 minutes, maximum time is 9 minutes for those top 10 ranking players.
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left;
 *     public TreeNode right;
 *     public TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    static TreeNode previous = null;
    public TreeNode BstToGst(TreeNode root) {
        if (root == null)
                return null;
            previous = null;
            traversalRightRootLeft(root);
            return root;
        }

        
        private static void traversalRightRootLeft(TreeNode root)
        {
            if(root.right != null)
            {
                traversalRightRootLeft(root.right);
            }

            // visit root
            
            var firstCheck = previous != null  ;            
            
            if(firstCheck)
                root.val += previous.val;
                
            previous = root; 
            

            if(root.left != null)
            {
                traversalRightRootLeft(root.left);
               // root.left.val += root.val;
            }
        }
}

Saturday, May 4, 2019

S&P 500 Index

Here is the link.


weekly contest 135

May 4, 2019

Introduction


It is my favorite weekly contest. I solved first two algorithms. I had some difficult time in the first algorithm, and then I came cross the problem with the second algorithm as well. I need to work hard and I should solve the second algorithm tree algorithm in less than 10 minutes.

My performance


Here is the snapshot of my ranking.


DALBAR PINPOINTS INVESTOR PAIN ANNUAL REPORT OF INVESTOR RETURNS SHOWS WHEN BIGGEST GAPS OCCURRED

In 30 years of monthly investor returns, DALBAR found that equity investors underperformed the S&P 500 to the greatest extent in October, 2008. In this month, equity investors lost 24.21% compared to an S&P loss of 16.80% for a net underperformance of 7.41 percentage points.

The next greatest underperformance occurred in March, 2000, when the S&P surged 9.78% but investors took home only 3.72% for an underperformance of 6.06%.

The underperformance results from bad investor decisions at critical points, the first in the face of severe market declines and the second when the equity market surged.

Underperformance in the face of maximum impact events is attributable to a lack of preparedness and is the subject of the recently released 21st Edition of DALBAR’s Quantitative Analysis of Investor Behavior (QAIB). The 21st Edition also reported:

2014 report


Case study: NYCB 6 year CD external transfer

May 4, 2019

Introduction


It is my personal finance research. I have to push myself to embrace the stock market and invest into equity market. I have to break CD 6 year term, and pay 12 month interest penalty, and bring those fund into Ameritrade.

External transfer


I like to document my CD here and my determination to say goodbye to 6 year CD, matured in 2012. I have to be able to learn how to invest on equity market, and then focus on long term growth more than 10 years.

Here are the summary of last 12 month IRA CD.



Linkedin profile study

Here is the profile.

I like to look into profiles and then search something ...

Celebration of Microsoft online code assessment success

May 4, 2019

Introduction


It is my personal finance research. I am a frugal person, and I know that I have to spend time to learn system design, and I do not want to go for an onsite in Seattle without any preparation. In other words, online assessment is just one hour practice. I like to celebrate it since I learn how to overcome difficulty last 4 years.

Hardwork and sharing


It is time for me to mark the success with my Leetcode profile. So I learn that it is so important for me to push myself to complete more algorithms on Leetcode.com, and also write down the journey, share with others.


Submission history


After the failure of Amazon code assessment this March, I learn that I have to push myself to work on problem solving through more practice.

I started to work on union find algorithm tag, and I found out that it is really hard to live with hard level algorithm. If I am not careful, it will take me a whole day to learn how to solve a hard level algorithm.

As I remember, it is better to go back to work on easy, medium level algorithm. This way I can learn better and learn fast compared to hard level algorithm.









Why it is so hard to pass Microsoft online code assessment?

May 4, 2019

Introduction


It is my short research topic. I worked on Leetcode, hackerrank starting from 2015 January, I did take 4 Microsoft online assessment from 2016 to 2019, one for each year. This year it is the first time I can pass online assessment. Why it is so hard?


Case study


I did start to work on Leetcode algorithm; In June 2018, I prepared to Amazon onsite in Seattle. I hired a coach who worked in Microsoft intern in Beijing. He told me that I should work on Leetcode easy level algorithms. My coaching sessions are here.

I started to work on Leetcode easy level algorithm. I failed the phone screen from Facebook at the end of July 2018. I spent another 3 months to finish all 200 easy level algorithms.

I also wrote a code assessment in 2018 from Microsoft. But I stumbled on infix expression using stack. My data structure skill is questionable. I wrote a discussion post on stackexchange.com, here is the link.

I took Amazon online assessment in March 2019, but I could not pass the test. I was nervous on second algorithm, even though I worked on the algorithm over 5 times at least on hackerrank.com from 2016 to 2017, and a few times in 2018 and so many peers on mock interview platform. There is another skill to write algorithm on assessment.

I asked a few times on interviewing.io using the same algorithm. I learned from a few candidates and watch and learn how to write a solution from scratch. Young generation with super talent likes to write everything from scratch, and he does not need to copy and paste the code; everything is his head; Just simple while loop and a few explanations. I wrote one blog here saying that I learn first how to write. Here is the case study on union find algorithm 947 remove stones.

I passed one online assessment in 2017, but no more assessment in 2018 from Amazon, 2018 phone screen I passed and then onsite, 2019 I failed Amazon online code assessment.

So I was so surprised to get contacted by Microsoft recruiter again, I started to prepare April Microsoft online assessment. I know that I have to push myself to get used to new algorithms and came out the optimal solution in one hour setting. Otherwise it will not work.

I already solved 395 algorithms on Leetcode.com. I also played over 30 weekly contest and then started to practice mock interviews on Leetcode.com. Here are my celebration blogs on Leetcode algorithms.

I had 48 hours to work on the assessment once I got the link, but I took extra day last long weekend. I did practice 4 days and worked on 50 algorithms, and then I stumbled on a few algorithms. I wrote down my experience very carefully. I know that the weakness is something I should work on next.

How I pass Microsoft online assessment?


I passed the online assessment first time in my life this April. I learn to be humble, and keep learning and practice.

If I have time, I like to write more about algorithm practice and share on Leetcode.com.

I put together a github page called online assessment preparation. 




100个cold email, 50个coffee chat后,来说说如何在美国net working

Here is the post.


iao (Sisi) Xue

Here is the linkedin profile.

S姐日谈|好久不见,来和大家谈谈心 is her wechat public profile.



心理情绪:







职场干货:








留学教育:













好书推荐:





关于S:



Case study: Data scientist linkedin profile study

May 4, 2019

Introduction


It is time for me to educate myself more on personal finance. I like to case study one linkedin profile, and learn how to learn finance as a self-learner. I believe that I met the person on mock interview, and had discussion on one algorithm together at least 50 minutes.


Case study


Here is the linkedin profile.

First, I like to learn two master degree program, one is university of Southern California, master of science, and then one more is George Washington University, school of business, business analytics.

I like to check ranking of George Washington University. Ranking is 34th in United States.

I also like to study Lime.com and relationship with Uber.com, and a hiring manager used to work at Uber.



Investing Insights: Retiring Overseas, Robo-Advisors, Short-Term Bonds, and More

Here is the link.


Managed Payout Fund (VPGDX)

Here is the link.


How to consolidate your retirement accounts - Vanguard

Here is the link.

6:00 - 7:38/ 8:59


The first year
The setup
401(k) = $250,000
403(b) = $60,000
IRA = $200,000
Social Security = $975/ month
Pension = $445/ month
Possible freelance = $200/ month

6:18/8:59

Marsha consolidates her 401(k) and 403(b) into her IRA = $510,000.
Marsha invests her IRA savings in Vanguard Managed payout Growth and Distributed Fund = $1,926/ month (estimated initial payout in 2010).

$1,926 (Managed Payout Growth and Distributed Fund - estimated initial monthly payout in 2010)

$975 (social security)
+445 (pension)

----------------
$3,346 (estimated)

$486,888 remaining savings balance:

Friday, May 3, 2019

10 Ways Successful People Stay Calm

Here is the link.


16 Rich Habits

Here is the link.

17 Motivating Quotes About Becoming Rich

Here is the link.

1. “It’s simple arithmetic: Your income can grow only to the extent that you do.” —T. Harv Eker

2. “Formal education will make you a living; self-education will make you a fortune.” —Jim Rohn

3. “The only difference between a rich person and a poor person is how they use their time.” —Robert Kiyosaki

4. “The more you learn, the more you earn.” ―Frank Clark

5. “Before you can become a millionaire, you must learn to think like one. You must learn how to motivate yourself to counter fear with courage.” —Thomas J. Stanley

6. “You can’t work three hours a week and make $100,000. Get rich quick doesn’t work. Crock pot mentality always defeats microwave mentality!” —Dave Ramsey

7. “An investment in knowledge pays the best dividends.” —Benjamin Franklin

8. “Fortune sides with him who dares.” —Virgil

9. “Rich people have small TVs and big libraries, and poor people have small libraries and big TVs.” —Zig Ziglar

10. “I have about concluded that wealth is a state of mind, and that anyone can acquire a wealthy state of mind by thinking rich thoughts.” —Edward Young

11. “All riches have their origin in mind. Wealth is in ideas—not money.” —Robert Collier

12. “Empty pockets never held anyone back. Only empty heads and empty hearts can do that.” —Norman Vincent Peale

13. “Every day is a bank account, and time is our currency. No one is rich, no one is poor, we’ve got 24 hours each.” —Christopher Rice

14. “What’s keeping you from being rich? In most cases it’s simply a lack of belief. In order to become rich, you must believe you can do it, and you must take the actions necessary to achieve your goal.” —Suze Orman

15. “Wealth is largely the result of habit.” —John Jacob Astor

16. “All achievements, all earned riches, have their beginning in an idea.” —Napoleon Hill

17. “Today the greatest single source of wealth is between your ears.” —Brian Tracy

Bond Rating Agencies

Here is the link.


What are the biggest risks of fixed-income investing?

Here is the link.

The biggest risks of bonds and other fixed-income investments are interest rate risk, credit risk and inflation risk. There are other risks to bear in mind, such as the call risk, but they only apply in a limited number of situations.