Tuesday, July 28, 2020

System design: What is a reverse proxy server?

Here is the article from NGINX.

I like to put together my notes:

A proxy server is a go‑between or intermediary server that forwards requests for content from multiple clients to different servers across the Internet. A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.

What is a proxy server? 
A proxy server
a go‑between or intermediary server
forward requests for content 
from multiple clients to different servers across the Internet. 

Where is a proxy server to stay? 

A reverse proxy server
a type of proxy server 
typically sit behind the firewall in a private network
direct client requests to the appropriate backend server. 

What is a proxy server? Explain using your own words. 

A reverse proxy
an additional level of abstraction and control
the smooth flow of network traffic between clients and servers.

Additional layer of abstraction and control


Sunday, July 26, 2020

System design: How to prepare myself to be a best learner?

July 26, 2020

Introduction


It is my short research about how to be a best learner on system design next two weeks. It is not easy, but I like to put together some creative ideas.

Facebook system design 


I like to look up Leetcode system design tagged with Facebook.

Follow up on July 27, 2020
I do believe that a best learner should be a good reader. I should push myself to read articles and then take notes, and over hours reading and short researches on small topics will lead me to be a great learner. 

I try not to watch youtube system design youtube videos this time. I do think that a good learner should pick up so many things to learn through reading instead. It is more active and I need to write down those names who provide quality content over years.

Facebook onsite: Study topics

July 26, 2020

Introduction


It is important for me to review and learn those topics very well in next two to three weeks.  I need to make a complete check list and ensure that I can understand the basics.

Topics to review


Some topics you should be familiar with:
- Concurrency (threads, deadlock, starvation, consistency, coherence)
- Networking (IPC, TCP/IP)
- Abstraction (understanding how OS, filesystem, and database works)
- Real-world performance (relative performance RAM, disk, your network, SSD)
- Availability and Reliability (durability, understanding how things can fail) -Data storage (RAM vs. durable storage,
compression, byte sizes)
- CAP Theorem
- Byte math

A Technical Overview of Kubernetes (CoreOS Fest 2015)

Here is the link.


INFRASTRUCTURE & OPERATIONS - Painless container management with GKE & Kubernetes

Here is the link. 

Kubernetes is leading the charge into the next generation of cloud computing. With a vibrant community, this open project is defining the APIs that let you use the same techniques that Google uses internally. Workload portability is a reality - Kubernetes can work on any cloud or in your own datacenters, all with the same API and tools. Google Container Engine streamlines it even further, offering you a managed container cluster with just a few clicks. Speakers: Brendan Burns & Tim Hockin, Google


Brendan Burns - Microsoft Distinguished engineer

July 26, 2020

Introduction


It is my short research about the author of book I am reading second day. It is called "Designing distributed systems - Patterns and paradigms for scalable, reliable services".

Brendan burns

I spent one hour to go over the book and see if I can learn something quickly. System design interview preparation is the art, and I do like to take some risk this time for hunting for good learning material, asking friends, and get connected to people in my social circle.

I asked my friend who works at NVIDA senior machine learning engineer, Dr. Liu recommended me the book.


Facebook onsite: Preparation - ask a friend

July 26, 2020

Introduction


I got an offer from my friend, used to be my coach back in 2018 for Seattle prime video group onsite interview. He recently joined Google and left Indeed. So I like to learn more about how to prepare Facebook onsite interview. 

My notes


He recommended me to work on Leetcode high frequency Facebook algorithms. Usually Facebook asks the exactly same question from Leetcode. 

Focus on algorithm. It is hard to remove bias from system design interview. Make sure that I can solve all the algorithm problems on onsite interviews. 

System design: Ask a friend

July 26, 2020

Introduction


I chose to ask my friend met in my nephew's party back in 2015. She is senior machine learning engineer and joined NVIDA back in 2015. She recommended me to read the book. 

A system design book


I spent a few hours to read the book, and I like to read more about it today. 

Designing distributed systems - patterns and paradigms for scalable, reliable services.

Brendan Burns

Linkedin Liu Xin - Here is the link.

Good job! Dr. Liu!




CAP theorem - P is tough to remember - Partition tolerance

July 26, 2020

Here is the link. 

CAP theorem

The CAP theorem (coined by Eric Brewer) talks about the trade-off between consistency and availability you have to make in your distributed system. This video describes what it is, and how it impacts your system design.

An example - a bank, one customer, two ATM, network between two ATMS

One customer - two ATMs

What if something breaks?

consistent view of balance

ATM broken or network problem

partition - suffer partition

Consistent design

Do my best - partition heals - More available

Both consistence - available design

Real world - degree of consistency - degree of available

Partially available design
. Deposit: yes
Withdrawls: small and rate limited
Balance info: tentative


The CAP theorem

Formalize the trade-off between consistency and availability in the presence of partitions.






Saturday, July 25, 2020

Storing hundreds of millions of simple key-value pairs in Redis

Here is the link.


Shard (database architecture)

Here is the article. 


Sharding & IDs at Instagram

Here is the link.

With more than 25 photos and 90 likes every second, we store a lot of data here at Instagram. To make sure all of our important data fits into memory and is available quickly for our users, we’ve begun to shard our data — in other words, place the data in many smaller buckets, each holding a part of the data.




Friday, July 24, 2020

System design: Instagram Architecture: 14 Million Users, Terabytes Of Photos, 100s Of Instances, Dozens Of Technologies

Here is the link. 


INTC stock: Learn to be a smart investor

July 24, 2020

Introduction


It is so hard for me to find top intelligent investor. How to think and how to understand the market swings? I like to look into those comments from INTC investors. 

Analysis


I am looking for good thinkers:

Hold your Intel shares strong, one of the most solid and most profitable companies in the tech world. Do not let those inexperience millennials and Panic earning gamblers mislead you. Look at the After Hour Panic Sell when Q1 release on 4/23, where price dipped -7%, and how it recovered the following trading day, and understand the reasons behind the panic sells and the recover, the same pattern will likely to guide you the next day of trading.

Intel (Intc) is likely to open at $57 range and trading between $56 low to $59 low possibly $60.

If you look at the history of Intel after earnings, for example Q1'2020 earning released after hours on 4/23/20 at 2PM Pacific time, the after hours trading price dropped almost -7% after hours from closing price of $58.7 to $54.9 after hours. 

The next morning 4/24/2020, it opened at $56.2, -4% drop from prior day closing price, much Higher than the prior day after hours. Also during the middle of the trade hours on 4/24/2020, the stock price gradually recovered to $58 in mid session then fully recovered $58.9 at the end of the day. 

If you look into the reason of why after Q1'20 earning on 4/23 after hours stock would drop -7%, it was because Intel was delayed in 10 Nanometer scale production and 7 Nanometer was postponed, but the earnings and revenue growth was exceeding expectation, so on 4/24/2020, after panic gamblers had gone during after hours, it opened with a narrower price loss and recovered during the follwing day. Q2'20 after hours 7/23 to 7/24 look like the similar situation to me. 

After Hours Panic sell from those Earning Gamblers who do not know a damn of the company and financials. The Next Morning stock recovered and continued into nearly full recovery during the mid day next day, eventually close same level.


INTC stock: Learn more about business

July 24, 2020

Introduction


It is tough for me to catch up more about Intel business. So I went to Yaoo->Finance->Conversation underneath stock page.

INTC stock


I like to review intel stock and learn more about the following content:

Here is the page.

Intel expecting to make over $4 per share for 2020, what is the issue here? A delay while no one can afford chips and upgrades currently is not all that bad of a deal. Balance sheet looks like INTC has double the assets to liabilities by about 70 billion.

Intel also has made over $20 earnings over last 10 years than what it is currently trading which should all be in the bank. There are double the assets to liabilities. We are talking about 70 billion vs AMD 3 billion on the balance sheets.

AMD market cap is close to 80B
INTC market cap is close to 200B

Intel has AMD's market cap in asset value.
Is my analysis correct?

Intel expecting again $4.50 about this year as it raised guidance a little, it just wont have the latest chips ready till next year. I think next year is a better time to release the chips.

AMD $3B of assets which will grow some however trading 20x assets minus liabilities.

INTC is trading about 3x Assets to liabilities.

No brainer this is getting given away at todays price. IMO today is a buy around $50 easy. Intel researches, develops and sells other technologies other than CPU's.

The above is just an investor's analysis. 

My favorite comments:

Lost 40 BILLION in valuation while delivering great earnings. Zero patience in this market due to momentum based trading algos.



Actionable Items


July 29, 2020

I did research on Lisa su and also AMD stock early in July, my hidden jealous was not so good and it affected my decision making. Now my position of Intel stock has 7% loss. I should purchase half of AMD to support Lisa Su and AMD instead. 



Interviewing.io system design show case:

July 24, 2020

Introduction

It took me near one hour to watch one of showcase on interviewing.io. I like to write down some notes about the showcase interview.

Showcase of system design.

I will add more later.

Facebook onsite: Three weeks learner - Amazing learner

July 24, 2020

Introduction


It is such great experience to go over two month preparation for Facebook phone screen. Everything runs smoothly, work, preparation and practice. I have learned so many lessons as a software programmer, I do believe that most important thing is to train myself and push myself hard to be a problem solver. 

Three weeks learner


I like to adapt to be a learner and also take some time to look into system design, and also work on nonstop on algorithm practice as well. 

I did ask a few friends met on interviewing.io last two years, and then quickly I got guidelines for my system design study. 

Amazing linkedin and interviewing.io to make world connected. Here is my github page. 

INTC stock: 15% plunge of Intel stock

July 24, 2020

Introduction


It is my favorite company Intel and the stock. I did make purchase today.

INTC 170 shares



Wednesday, July 22, 2020

System design: Distributed database

I plan to watch this video in short future.
Here is the link.


System design advice: 10 - 15 popular system design questions

For system design, I would say do as many mock interviews in interviewing.io as possible. Prepare through 10-15 popular system design questions. Think about fault tolerance, alternate options and make sure you can explain the props and cons of the approach. Good luck with the interview.


Leetcode 1040: Longest duplicate string


Longest duplicate string is binary search with hash

Binary search for the length, use Robin karp hash

Question about Leetcode 1040:



There is no pattern string, how to find which one to compare. Save all the same length one in the hashset? Rabin hash is to compare to given a pattern string.

Here is my gist saved. I will play Java code and see how it works. 



System design: Youtube channel recommendations

July 22, 2020

Introduction


It is day one again for my system design study. I also need to ask friends on Linkedin.com first. I met them as an interviewer.

VMWARE engineer's recommendation


There is another one by Gaurav Sen. you can check that as well. But Tech Dummies has really good stuff. He explains well.

  • Additionally there is a system design channel on YouTube by Narendra. You can follow that.
  • It’s call tech dummies




Weekend marathon on Leetcode mock interview phone screen

July 18, 2020

It is so important for me to work on my crafting skills. I started marathon to work on Leetcode mock interview phone screen last Friday evening.

My marathon


I am not sure how many algorithms I can complete in weekends. I have 5 mock interviews. So far, I completed over 10 algorithms.


Tuesday, July 21, 2020

华尔街有一句名言:“buy on rumor. Sell on news.“

不要赌财报!不要在财报日当天做day trade,因为上下幅度会很大,而且回调速度很快,人根本反应不过来(大神除外)。另外,华尔街有一句名言:“buy on rumor. Sell on news.“ 如果你特别看好一家公司,你可以提前几天埋伏做多该公司股票。然后在财报正式出来之前,我建议大家把股票卖了。财报出来之后,价格波动会很大,而且股价怎么走,我们散户是永远无法干预的。就算财报利好,股价也不一定会涨。财报利空,股价也不一定会跌。无论在哪个股票市场,我们散户永远不是庄家,切记切记

I like to look into this viewpoint. Day trading is hard to play. Market takes a random walk. I have to think clearly what I should do as an investor.


能源板块大涨

Here is the link.

美股分析:热点板块切换持续出现一个特征,那就是循环轮动,皇帝轮流做。这个规律如何运用?今天久违的能源板块大涨,是否死猫跳?原油突破开始反弹?明日盘后特斯拉财报,即将买定离手,怎么赌?


choose stock with biggest capital or largest volume.

TSLA - for example

ETF - 6%
one to two month losses -




Algorithm: Find longest repeated substring

Here is the link. 


Algorithm: Find longest repeated substring without overlap

Here is my github page for the algorithm. 


Stocks making the biggest moves in the premarket: Halliburton, Chevron, eBay, Delta & more

Here is the article.


Leetcode solved problem: From 461 to 492

July 21, 2020

Introduction

It is important for me to push myself to write code every day. I did not do that since January 2020, coronavius, running to prepare for Vancouver sun run, and then hay fever, and stock market crashes. Starting from May 28, 2020, I had to prepare for Facebook phone screen, and then I started to work on algorithms again. I only solved 32 new algorithms so far.

32 algorithms

I am so glad to learn the benefit to write code for those simple algorithms. Even the tough one, it only took me less than three or four hours to make it work.

Things I like to talk about is about Trie data structure, using stack, and other things like tree algorithms.

Facts to review

It takes 3 days nonstop practice, so that I can find out how many weakness I have in my thinking process and drafting process.

After my first break-down, it took me 40 minutes to go back to think efficiently using knightdial algorithm. I learn that I have to let my brain get used to those stress, and then I can perform better.

At my peak time, it only takes me five minutes to recall the whole thing, after six months break, the first one will take me 40 minutes. To prepare for Facebook phone screen, I need something like 2 - 3 minutes to refresh my muscle memory.


Two hours research: Oil stock 10% gain

Here is the link.

I am studying Chevron, and deal to purchase Nobel energy in 5 billion dollars.

Inflations -> good structure company with a lot of debt - cash deal to purchase stock of Nobel

Debt-burden energy company

Energy - all sectors - analyze things - who is good credit star rating ...


How do I handle my USA stock portfolio?

Five ideas to get back to more sports life

July 21, 2020

Introduction


It is tough project to work on. I like to lose 10 lb, and also play more tennis sports as well. I like to write down five ideas to go back to more sports life.

Five ideas 



  1. Need to learn how to balance work, algorithm practice, stock investment and sports activities; 
  2. Put sports first after the work and in the weekends; 
  3. Start to read more about weight control, running and tennis sports;
  4. Plan to finish first 20 tennis workout in one week; 
  5. Plan to hike a few times in short future. 

Five hours to relax after Facebook phone screen

I spent most of time inside my home office last Friday after the work. I only took one time 30 minutes break to walk around the neighborhood I live last Saturday. I definitely needed to take a break, and walk and run and play sports, go out to meet people.

Intensive study is great for preparation. After one hour phone screen, I went out to play tennis sports.

First hour - watch a double game live in central park burnaby, I knew all those players. 
Second hour - watch another double game
Third hour - start to work on hitting against the wall
Fourth hour - take multiple breaks
Fifth hour - hit against the wall again.

How to give good impression to a Facebook manager through phone screen?

As a reminder, please keep these 4 criteria in mind during your technical interview:
  • Communication: Ask clarifying questions around the problem before solving 
  • Speed: One of our values here is moving fast 
  • Verification and testing: bug free as possible, talking through edge cases 
  • Problem-solving: Finding a working solution


Based on my own experience, the second algorithm is hard to approach the problem using dynamic programming. I like to push myself think about more about the solution, and then I remember that it is better to have a working solution. I only have 20 minutes after the first algorithm. I have to be able to write the code and test the code and make sure it works. 

To lower the risk, I did not choose to take risk to go for analysis of dynamic programming solution. It is tough decision. 

Go to brute force solution second one, if I have time, then I will write an optimal solution. It is not easy to approach the problem, but I have to solve it first. 

Understand what is thinking like a programmer

Understand what is thinking like a manager

Crafting skills - how many hours minimal to maintain the level?

July 21, 2020

Introduction


It is my short project to work on. I have to evaluate how many hours minimal one month in order to maintain my crafting skills to the certain level. It is hard for me to measure my own curiosity, and ability to stretch my brain muscle to think a hard level algorithm in less than five minutes.

How many hours minimal to maintain the level?  


I do think that I deserve to have a good career and enjoy the life as well. In order for me to work and stay competitive, I like to push myself to improve my crafting skills.

40 hours
20 hours
10 hours
5 hours

I do think that it is important for me to practice as many hours as possible. I should think about 40 hours for the first week, and then reduce hours to less the second week. There are so many things for me to work on.




What is most important in Facebook phone screen?

July 21, 2020

Introduction


It is only phone screen I had this year in 2020. I do appreciate the chance to be selected, so that I spent two months to learn and review a lot of algorithms. Preparation is most important, and also I do believe that it is also important to promote how hard I have to push myself to share my progress, what I learn, and what is challenging. 

Preparation


It takes time for me to learn and get used to think how to solve algorithm quickly. I do think that I have to go over at least 100 algorithms before the phone screen. 

During Facebook phone screen


I do think that it is important for me to learn how to communicate, ask clarification question, and also make sure that I can write executable code, working solution, and moving fast in 45 minutes. 

I understand that it is important for me to push myself, and let myself to take some risk, and go for a working solution, make sure that I can produce something working to solve the problem.

In other words, I have to take less optimal solution if the time is not enough for me to analyze and think clearly for a tough algorithm.



Why should I push myself very hard three days before Facebook phone screen?

July 21, 2020

Introduction


I learn from mistakes I made through Leetcode easy level tree algorithms. I understand that it is important for me to be a responsible person, how come I can take a job if I can not produce high quality of code in less than 10 to 15 minutes, and let the fact stay true for so many years. It is my 10th year on the same job. I have enough time to learn and overcome any weakness I find.

Push myself hard


It is so interesting to learn how our brain works under stress. Also it is about 53 year old engineer, or just a programmer.


How to control risk on Facebook phone screen?

July 21, 2020

Introduction


I like to talk about how to control risk on Facebook phone screen. I do think that there are so many algorithms for me to review, and also there are so many classical algorithms for me to learn and some of them are really hard level algorithms. 

Sending out messages on Linkedin


I did send out over 10 messages on Linkedin.com, and then started to get myself understand importance of project. I got a friend to offer me four mock interview to work on communication skills.

49 tagged blogs about 2020 Facebook phone screen


I do think that it is important for me to work on those algorithm and data structure. It is vital for a software programmer to survive, no matter it is good time or hard time. What is it? I do think that problem solving ability, and crafting skills, and also ability to learn.

Here is the link.

The risk


It is high probability for me to fail Facebook phone screen. Even though I was lucky to be selected for my first onsite from Facebook. This time it is more serious and more competitive to stay on top of candidates.

I like to make sure that I do my best as I can. Enjoy the learning. Also it is important for me to find weakness to work on.

I did start my first marathon weekend to work on algorithm non-stopped for 3 days in the row. I knew the difference this time, I do think that I have to really work on so many things in terms of Leetcode discuss post, analyze of algorithms, how to stay on track to solve a simple problem. Compared to my previous experience from 2015 to 2019, I tried to memorize the solutions for as many algorithms as I can.








My investment community on wechat

Talk about algorithm practice from a stock investor viewpoint

May 28 - July 20 two months preparation for Facebook phone screen

Here is github page for my preparation repository. 

It is a nice journey, and I also worked on a few small projects at work. I got motivated and push myself to write more code at work as well.

Is it possible for me to be a mediocre programmer to be a competitive one? Preparation is so important, and I have to be humble and write easy level algorithms. Stay confident, take risk to learn basic things. Crafting skills are important, but without practice, there is no skills.


Cannot stop practice algorithm!

How to lose 10 lbs in 100 hours tennis sport this summer?

Tennis sports and my sports family


I went back to tennis court after one hour phone screen. I only took less than 30 minutes walk around the community last weekend. I was busy and sit whole day to review and code algorithm nonstopped. It is important for me to go back to tennis court, and then meet my tennis family.

16 tennis courts and wall

I know more than hundred people on tennis court. Any time in summer time, I can meet people and say hi. Every one of them is potential a good friend, who can help me relax and hit tennis with me, help me quickly lose those body fat. My weight is 196 lb after so many days away from tennis court.

I did spend time to watch best tennis match on double match, and I chatted with a young chinese girl in her eight year old, her father was playing double tennis, her 10 year old brother played tennis against the wall. I mainly asked about coronavirus, school stuff. She likes drawing.

I spent over four hours on tennis court. I talked to over 20 people, and watched games, and also played against the wall.

Here are highlights:

1. Dress properly - casul shoes, tennis shoes, and tennis clothing
2. Bring water bottom, chat with people
3. Work on my big muscles, run and hit against the wall half hour; take break; half hour;
4. feel my body, and examine if any muscle, bone and joints are functioning properly.

Usually I run one hour before I play tennis. Usually it is better for me to run 5000 meters around central park two rounds. Warm up first, and then I can start to play against wall half hour. And then play some matches if I have chance.

Most of important, meet people and chat, and prepare for future opportunity to play together.

It is my Canadian family on tennis court.

Get smart on things to work on

Three biggest problems last 5 years on those over 60 tree algorithms

Three things improved last five year through those Leetcode tree algorithms

Two hours review of tree algorithms on Leetcode on July 20, 2020

July 22, 2020

Introduction

It is the first time I like to go over the tree algorithms on Leetcode.com. I started from hard level tree algorithms, and medium level algorithms next. I spent over two hours and then I was so busy to review and learn a few things. 

My favorite algorithm No. 1

It is my most favorite algorithm to review. 

No. 2

No. 3 

What is most important in a software programmer life?

July 21, 2020

Introduction

It is hard for me to figure out what is most important as a software programmer. But I did remember those days how I struggled to stay at home two weeks after March 19, 2020. 

Health is most important

Stay competitive is very important

Stay fit is most important

Stay financial independent is very important

Other things are important as well - keep myself to get connected to hard working people. 

How many algorithms I worked on last weekend?

Say goodbye to Facebook phone screen

July 21, 2020


Introduction


It is such great journey to work with Facebook and then I had a phone screen on July 20 2020. The phone screen was normal as 45 minutes, 2 algorithms to work on. I have to say goodbye to Facebook phone screen. 

Get organized

I have to continue to work on algorithm practice. I do think that the habit is good and healthy to code algorithm daily. I like to push myself to continue to practice, and also start to learn more about system design as well. 

Proverbs 28:19-20 A hard worker has plenty of food, but a person who chases fantasies ends up in poverty. The trustworthy person will get a rich reward, but a person who wants quick riches will get into trouble.

【箴二十八19】「耕种自己田地的,必得饱食;追随虚浮的,足受穷乏。」


Sunday, July 19, 2020

Leetcode discuss: 979. Distribute Coins in Binary Tree

Here is the link.

C# Need to work on a simple case study

July 18, 2020
  1. Distribute Coins in Binary Tree
Introduction
It is my first algorithm in Leetcode mock interview. I spent over 30 minutes to think about so many ways to break through the problem. Nothing can lead me to a simple solution.
Ideas I thought about in mock interview
I know that root node has coins with val, and it should take away val - 1 coins. But I continued to think which way to go, I tried to build a table.
      Root node
      /               \
Left subtree       Right subtree
I tried to think about from bottom up, leaf node has only one connection to parent node, up/ down two directions.
I also think about from root node, how to determine if left subtree has extra coins, or righ subtree has extra coins. It is impossible that both has extra coins.
Tree algorithms
It is totally different experience to solve tree algorithms after six month break. Recursive thinking is most challenge task.
Follow up
July 19, 2020 12:17 PM
Case study
A simple tree with root node (coins = 3) left child (coins 0) left.left child (coins 0)
The root node need to move away 2, left child need move one coin to add, left.left need move one coin to add, in total, there are 2.
Follow up 7/19/2020 1:32 PM
Case study
I need to work on a test case and see if I can figure out the coins move correctly or not.
image
The idea to calculate total coins moved is to calculate each edge what is number of coins to move from node to it's parent node. It is easy to apply a post order traversal. -1 means parent node sends a coin to it's child, +1 means that the node sends a coin to it's parent node.
The total coins moved is to add sum of each edge's absolute value.
In summary, using post order traversal, and also determine how many coins to move to parent node each time. Starting from leaf node, a node will consider it's children nodes and then add itself to the parent node.
The coins moved in the above diagram is 3.
Recursive function design
Apply post order traversal, recursive function will return number of coins to move in direction.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _979_distribute_coins_in_binary_tree
{
    public class TreeNode
    {
        public int val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(int x) { val = x; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var node0  = new TreeNode(0);
            var node0B = new TreeNode(0);
            var node0C = new TreeNode(0);
            var node4  = new TreeNode(4);
            var node0D = new TreeNode(0);
            var node3  = new TreeNode(3);
            var node0E = new TreeNode(0);

            node0.left   = node0B;
            node0.right  = node0C;

            node0B.left  = node4;
            node0B.right = node0D;

            node0C.left  = node3;
            node0C.right = node0E;

            DistributeCoins(node0);

            Console.WriteLine(coinsMoved);
        }

        public static int coinsMoved; 
        public static int DistributeCoins(TreeNode root)
        {
            if (root == null)
                return 0;

            coinsMoved = 0;

            postOrderTraversal(root);

            return coinsMoved;
        }

        /// <summary>
        /// https://leetcode.com/problems/distribute-coins-in-binary-tree/discuss/221939/C%2B%2B-with-picture-post-order-traversal
        /// go over the example in the above discuss 
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        public static int postOrderTraversal(TreeNode root)
        {
            if (root == null)
                return 0;

            var left  = postOrderTraversal(root.left);
            var right = postOrderTraversal(root.right);

            coinsMoved += Math.Abs(left) + Math.Abs(right);

            return left + right + root.val - 1;
        }
    }
}