Saturday, September 12, 2020

Lesson I learn from 2010 - at work and my life

I like to write down something about lesson I learn in 2010.  I will continue to organize better, and find some good lessons to learn from. 

2010

Life was so much joy to work as a full time job. I finally got one full time job again. My last full time job was from August 2006 to August 2007. This was the first year since I was new immigrant after I spent over 14 years in Florida from 1996 to 2010. 

The office building is almost brand new, and I had so many coworkers. We had whole floor and we only have less than 20 employees in office floor. I had to work with people and then learned so many things. I understood that I have time to develop a lot of skills. 

The full time job can bring a lot of things to my life and career. I will have chance to learn from my weakness and strength. 

In weekends I  started to enjoy hiking, and so many new things in my life, since I was in Florida over 14 years.  Since I could not get Canada permanent resident in the first application, I filed a lawsuit again Canada Federal court and then I got settlement outside the court. I learned important skills from the lawsuit in my life, in 2009. 

In 2010, I worried about my US status, and kept register one graduate course one credit using my rental income in Florida. 

I did not do very well on research on my dissertation. One of the ideas was to go back to Florida for graduate study if I could not make things work in the city of Vancouver. 

At work, I started to learn Microsoft Excel, Visual C#, and I was so busy so that I did not have time to learn CSS and html code, like reading a book like "headfirst CSS and Html. 

I can put together so many things, and my thoughts can be better after I spent time to work on them. Let me summarize the lessons I learned. 

Lessons I learned:
  1. Work on communication, specially on team environment. 
  2. Stay confident. Say goodbye to lack-of-confidence.
  3. Keep myself simple. Do one thing at a time. 
  4. 44 years old is my best time to learn new skills and also write a lot of code by going through practice. 
  5. Work on real estate market research. Renting is cheap, but I could not build wealth over long term through real estate. 
  6. My crafting skills were not good. I should start to look into good books to read like "The art of readable code ". I could save a lot of time when I worked on projects and improved quality of code and design. 
  7. I worked so hard, work more than eight hours at work, so many hours in the evening and weekends. 
  8. Get into professional meetup first, and then learn how to develop my skills to networking etc. 
  9. Plan ahead for 10 year ahead properly. I brought with me over $15,000 US dollar cash, with $38,000 dollars on US home equity loan, the condo price went down around $45,000 US dollars, only around $20,000 dollars on my US 401 K and IRA CD account. I had over 14 years in Florida and single all the time. Take some time to work on personal finance research first. 
  10. It is time for me to evaluate how I like to spend my life as a rich or a poor. Best time for me to learn how to build wealth should start from my early age, not until I got Canada permanent resident, until I had a full time job again. 
  11. Mental health is also related to how many wealth I already build. So I did not take risk to purchase a brand new condo around $150,000 Canadian dollar in 2010, I worried about job loss, bankruptcy, no one to fall back on. Florida real estate underwater around 2010 etc, a lot of underwater real estate properties.  

10 Lessons From My 10 Years at MP Lighting as a software programmer

 Sept. 12, 2020

Introduction

It is so surprising to come cross this medium article in my gmail inbox, "4 Lessons From My 4 Years at Facebook & Instagram as a Software Engineer". I read the article and I do think that it is a good idea to go over again and again, I should write something for my 10 years at my current job as a software programmer. 

4 lessons from my years article review

Here are highlights for those lessons:

  1. Product features across Discovery, Explore, Search, Location Pages, hashtage Pages, Location/Hashtag/Sticker stories, Save, Collections, Keyword Search, Integrity and privacy, and more recently shopping. 
  2. 4 top learning: Kill your darlings, "Simplest solution is usually the right one", the understanding importance of soft skills, (Extreme) ownership
My 10 lessons  from my 10 years at MP Lighting

I will think about and plan to write down something meaningful. My writing assignment for next two weeks. 

Here is the first one for the first year 2010. I will write more later. 

Good article helps me to stay away gambling on stock market

Sept. 12, 2020

Introduction

It is tough world when I work on stock market. I always have my weakness showing up, for example, money management issue in my life. But when market is downward, it is so challenge to stop once I form this gambling habit. But I do not know how long it forms, I know alcohol addiction only takes one week to two weeks. 

Get back to normal life

I like to get back to normal life. When market is down, I like to learn more about betting, probability, risk management, money management. And try to preserve my limit capital, $64,000. Even though I know the market risk, I did put back $20,000 on market to purchase 1000 share SU.TO last Friday morning. 

A good programmer cannot be good if I can not solve my money management problem. Gambling for a small amount is fine, but huge amount with 10 year saving, without a roof overhead, it is tough and dangerous. 

Try ideas

So many ideas I should try to stay away from the market. I like to wait that market crashes as normal first, and then think about opportunities. 

I spent 30 minutes to read the following article, and check author's instagram profile as well. 

Here is the article. 


Thursday, September 10, 2020

Can I learn how to teach money management in one day?

 Sept. 10, 2020

Introduction

I almost cried when I uploaded the sheet with $3000 dollars loss in one day on my TFSA account, even though I did research and also wrote down my lesson after over $2000 dollars in less than three days. But I allowed it happen again. I did not pay responsibility to learn things properly, maybe starting from 18 years old, I did not do homework properly. I did not follow the steps and allow myself to skip homework, never build good habit to do money management. 

Relax and one day I can teach

I will write down something here later, maybe 3 months or 6 months. I learn how to be a good investor on stock market. Stay tuned. 



How fast I can learn in stock market?

 Sept. 10, 2020

Introduction

Based on common statistics, 10 investors on stock market, 8 break even, 2 lose, 1 win. I start to learn what is my biggest mistake as a beginner as well. But I do not learn fast, I need to lose all my six month gains from June 5 to Sept. 10, and then I found out that I am gambling, not investing. 

How fast? Not how fast. Learn proper way

I paid $200 Canadian dollars using Paypal to pay SJTU alumni who works on stock trading in Shanghai. But I did not learn. I just had conversation with him through zoom, later he chatted with us in wechat group four of us - all ladies to work on stock market investment. 

I came cross this video last weekend. Since I had over $2000 dollars loss, so I spent time to watch the video. Over 10 times. Here is one of blogs. 


Leetcode discuss: 889. Construct Binary Tree from Preorder and Postorder Traversal

 Here is the link. 

C# Find right subtree root node in postorder traversal list

Sept. 10, 2020
889. Construct Binary Tree from Preorder and Postorder Traversal

Introduction

The idea to solve the problem is simple and easy to figure out. I will go over a simple example to explain it first, but the coding is hard and I needed to use Microsoft Visual studio debugger and then figure out how to set condition if statement to terminate subtree. My bug is to put all nodes in right subtree, and never set left subtree for some reason.

Case study
pre = [1,2,4,5,3,6,7]
post = [4,5,2,6,7,3,1]
The root node is the first one in preorder, and also last one in post order. The idea is to work on next one, post order traveral list next to last is 3, which is right subtree root node.

By looking up inorder traversal list, the index position of 3 is 4, so preorder list is divided into left subtree [2, 4, 5], right subtree [3, 6, 7].

The idea is to put postorder traversal list to a stack, and keep working on a number at a time.

What is challenge part of problem solving? I did not know until I found the code does not put left child for any subtree.

Check if next node in post order stack is not in current subtree
It took me over 15 minutes debugging to find out that if condition statement is needed. First, I have to simplify the test case, and make sure that simple test works.
pre = [1, 2, 3]
post = [2, 3, 1]

When I interviewed people using the algorithm recently as a mock interviewer, one chose not to write the code, but he came out the idea to find right subtree's root node; Second one did not add if condition statement to enclose root.right and root.left statement. As an interviewer, I did not write the code first, so I did not know the issue. In other words, I need to point out the design issue, it is important part of recursive thinking challenge most people fail in their first writing.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _889_preorder_and_postorder
{
    class Program
    {
        public class TreeNode {
            public int val;
            public TreeNode left;
            public TreeNode right;
            public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
                this.val = val;
                this.left = left;
                this.right = right;
            }
        }

        static void Main(string[] args)
        {
            //var pre = new int[]{1,2,4,5,3,6,7};
            //var post = new int[]{4,5,2,6,7,3,1};

            var pre  = new int[] { 1, 2, 3 };
            var post = new int[] { 2, 3, 1 };

            var root = ConstructFromPrePost(pre, post);
        }

        /// pre  = [1,2,4,5,3,6,7]
        /// post = [4,5,2,6,7,3,1]
        /// Output: [1,2,3,4,5,6,7]
        /// space complexity: O(N), N is total number of nodes
        /// time complexity: O(N), lookup using hashMap O(1), 
        public static TreeNode ConstructFromPrePost(int[] pre, int[] post) {
            if (pre == null || post == null || pre.Length != post.Length)
            {
                return null;
            }

            var stack = new Stack<int>(post);
            var map = new Dictionary<int, int>();
            for (int i = 0; i < pre.Length; i++)
            {
                map.Add(pre[i], i);
            }

            // construct the tree using postorder, and then find right subtree
            // root node using postorder traversal
            return constructTreeUsingPostOrder(pre, 0, pre.Length - 1, stack, map);
        }

        private static TreeNode constructTreeUsingPostOrder(int[] pre, int preStart, int preEnd, Stack<int> post, Dictionary<int, int> map)
        {
            if (post.Count == 0 || preStart > preEnd)
            {
                return null; 
            }

            var rootVal = post.Pop();
            var root = new TreeNode(rootVal);

            if (post.Count == 0)
            {
                return root; 
            }

            var rightValue = post.Peek();
            var rightIndex = map[rightValue];

            if (rightIndex <= preEnd && rightIndex >= preStart) // added after debugging - if it is in the subtree
            {
                root.right = constructTreeUsingPostOrder(pre, rightIndex, preEnd, post, map);
                root.left  = constructTreeUsingPostOrder(pre, preStart + 1, rightIndex - 1, post, map);
            }            

            return root; 
        }
    }
}

I might be a gambler. I need to learn to form a good habit after good research.

 Sept. 10, 2020

Introduction

It is human nature to get addicted to invest on stock market. After short term big loss, I need to work on my money management problem first. Avoid big loss as a beginner on stock market. 

Money management

I have this problem over 30 years. I grew up with a mom who is biased on treating six siblings. I grew up with jealous of getting favor treat from my mom starting from very young. 

I did not learn money management. I live a single life and do not talk about money management. Until this market correction, I just found out that I need to learn. 

Being frugal. Delay gratification. Hard working. Do research. Try to make a small position win. Do not bet too big. Common mistake for a beginner is to avoid big loss. 

I need to learn again. After 30 years, it is hard for me to discipline myself. 


Research -> Corrections -> Push hard to make it happen

 Research: Big mistakes as a beginner in stock market

Avoid big loss: I learn that it is important for me to avoid big loss. I did not learn it very well. I took $3000 dollars, and then another $3000 dollars on Sept. 10, 2020

Push hard to make it happen

I like to sell 90% of positions in my TFSA account, until I can build habit to set trail stop limit, and also set daily loss up-limit $500 dollars. 

As a beginner, I have to limit the size of investment. Otherwise it is going to be gambling. Market risk is avoidable with the trail limit stop. 


Do not worry for today big loss - I used to waste $40,000 dollars on less than three year on Citi bank credit card expenses

 Sept. 10, 2020

Introduction

It is my big battle for money management. I have to avoid big loss. I started to learn how to invest on stock market, but I did not learn the rules, and how to follow the rules. No. 1, avoid big loss. 

My bad habit - money management - over 30 years

Once I form the bad habit, it is hard for me to correct the behavior. I have to learn this lesson, Sept. 10, 2020, I made mistake not to set stop loss on over $60,000 dollars TFSA account. 

Actionable Items

Look at this positions on Sept. 10, 2020. This is not an investment daily report. It is gambling. I do not learn how to prevent market risk, set trail stop limit on my positions. Diversification and all other things are missing in my portfolio. 

I only can make $2000 dollars after tax, and one day I lost near $3000 dollars on one account. 




Stop big loss: It is hard for me to learn as a beginner

 Sept. 10, 2020

Introduction

I spent last weekend to learn the big mistake as a beginner. To avoid big loss, not allow too big size of position. I do not discipline my life whole half century. It is hard for me to learn the rule. I made mistake again, today my TFSA account has near $3000 dollars loss. 

I need to learn and stop the bad habit

I have money management problem. All my mistakes in last 30 years showed up in today result again. I was bullied before, so I did not learn how to avoid big loss. I paid $5000 US dollars vacation back in 2001, I paid near six relatives hotel and train tickets for 3 day vacation. I did not learn how to say NO. I did not learn how to manage my money, avoid scam from relatives, including my mom. 

All those bad habits do not get regulated and corrected in my last 10 year full time job. I am so worried about the consequence. 

I should learn the big mistake, and then avoid big mistake. 






Money managment problem: a beginner - stubborn - hard to learn

 Sept. 10, 2020

Introduction

As a beginner, I have to force myself to learn. I already lost all my six months earning over $6,000 dollars. I need to learn stop big loss. Never allow $400 dollars losses on my TFSA account in a day. Today I had over $3800 dollars loss. 

Stop loss - a beginner has to be humble

I have to document this problem, and remind myself never make this mistake again. I lost IMO.TO one day near $882.61 dollars. 


It is a bear market right now. I have to take risk, do not worry about missing out. Save my original capital. If I like to make money, I have to make it short, less than a few hours, take a full day off to watch the market. 

I need to build a simple habit to stop loss. If there is over $100 dollar loss, then I have to quit the market. 




If I like to learn day trading or short term trading, I have to avoid big loss like today. It only takes me less than 5 minutes to set loss. I should not worry about missing rebound or something else. 

I am a beginner. Do not set position too big. I should only allow myself to play with gains. Less than $6000 dollars. 

Actionable Items

Never allow myself to lose more than $500 dollars on my TFSA account in a day. I need to set trail stop limit. I swear to obey the rule. Time: 10:29 PM, 9/10/2020. 





Money management problem: I have problems to manage money - avoid big loss

 Sept. 10, 2020

Introduction

It is my six month stock investment experience. Through those experience, I learn how to take advantage of those stock swings, but today I suffered big loss again. Another $2,000 dollars loss on my TFSA account. I did not set stop loss again. Life is too tough to learn a lesson. I need to stop this investment game - it is a scam!

My Canada TFSA positions

I like to stop those positions, and sell them tomorrow morning when market opens. I will no longer hold positions overnight, and I like to take at least two months off the market. I need to go back to normal life, enjoy full time work, and learn algorithm and system design. Be a good engineer. 

Speculation, stock up and down. Vanguard total market index fund does not change that much. But my speculation and not diversified portfolio went down over 15% worst one. Less than one month ago, my TFSA account has $60,000 dollars on cash, only $6000 dollar on the market. 

My love of those easy money pushed me to be a such speculator. I tasted the loss and I need to confess that it is not a good habit to play the game, when the whole market is full of manipulation, and fear and greedy. 




Tuesday, September 8, 2020

CVE.TO stock: 2600 share, $5.54, $14,404 market value, loss -6.71%, -1036.50

 Sept. 8, 2020

Introduction

The stock market is downward and there is a big selloff. CVE.TO stock may have more losses. I have to manage the positions, and I like to make plans. 

CVE.TO 

I just realized that I have over $14,404 capital in the market. I need to learn how to invest long term on this stock CVE.TO. 

I will review intrinsic value, and plan how to reduce the loss and get some return in next six to twelve months. 


My stop loss order


Average cost: $5.90

Market price: $5.54 

3 months lowest point. Stay positive. Be a long term investor. Every share I like to make profit $3.00 dollars. 

Plan to hold more than six months. No matter what is happening. 

Stop loss - sell when price drops, and buy lower price again. 

$3.00 x 2600 shares = $7800 dollars gains! 

$5000 dollar loss in a day: My TFSA positions - a beginner is hard to learn how to stop loss.

 Sept. 8, 2020

Introduction

It is important for a beginner to focus on how to stop loss; Stay away from wishful thinking. Market will do whatever it does. But as an investor, always stop big loss. 

My positions and $5000 dollar loss in a day








Actionable Items

I do think that all my money management problems in last 30 years showed up in my stock investment last six months. Stop big loss, and keep small wins, then I can build wealth. 

Learn new techniques and also apply quickly. Do not wait until there is $5,000 dollars loss. Try to focus on stop big loss, not always think about making money and purchase stock in cheapest price. 

The reason the cheaper price is that the company does not have stable income, and still in a lot of debt. So once the market is in correction, SU.TO and IMO.TO stocks has problems and loss is close to 10%. 


Risk management: Stop loss - I learned but I had to take over $3000 dollars a day on Sept. 8, 2020 first

 Sept. 8, 2020

Introduction

I am stubborn. I am not quick to learn and avoid big loss even though I spent over 3 days to learn big mistake as a beginner is not to stop big loss. My landlord also gave me warning after tennis play around 10:30 PM on tennis court, I did not set stop loss orders. I had my own plan. 

My plan did not work 


I sold over $10,000 dollars each for TRP.TO, PPL.TO and around $8000 dollars for ENB.TO, I bet around 8:30 AM around 3% rebound. But there is no rebound, market continued to crash and another 3% losses. I experienced over $3000 dollars loss. 

My big loss a day as a beginner

I am 53 year old. It is hard for me to take action quickly. I think that I am too stubborn to learn new tricks now. I have to experience over $3,000 dollars loss first, and then I will remember that pain of big loss. 




I started my first four stop orders 

 

Actionable Items

Lessons learned
Next time market crashes, I should focus on stop big loss first. Do not speculate how big the loss should be. You never know the losses. It may be so big and I could not afford the loss. 

To stay in the game, I have to discipline myself to stop big loss. As a 53 year old, stubborn, not easy adapt to new rules. I should force myself to follow the rules first. 

I should not base on my limit experience, speculate that market will only have less than 7% loss. 

Risk management: Stop big loss - as a beginner - it is important to put orders to stop loss

 Sept. 8, 2020

Introduction

It is my personality problem to manage money. So it shows up in stock investment as well, last 3 business day my USA Ameritrade.com has over $1000 dollars loss. I need to apply risk management. 

Trailing stop order

Every time I place an order, I need to set loss and manage risk of big loss. 






Order Type In Depth - Trailing Stop Limit Sell Order

 Here is the article. 

Step 1 – Enter a Trailing Stop Limit Sell Order

You have purchased 100 shares of XYZ for $66.34 per share (your Average Price) and want to limit your loss. You set a trailing stop limit order with the trailing amount 20 cents below the current market price of 61.90. The trailing amount is the amount used to calculate the initial stop price, by which you want the limit price to trail the stop price.

To do this, first create a SELL order, then click select TRAIL LIMIT in the Type field and enter 0.20 in the Trailing Amt field. In a trailing stop limit order, you specify a stop price and either a limit price or a limit offset. In this example, we are going to set the limit offset; the limit price is then calculated as Stop Price – Limit Offset. You enter a stop price of 61.70 and a limit offset of 0.10. You submit the order.

Step 2 – Order Transmitted

You transmit your order. The current market price of XYZ is $61.90, the initial stop price is $61.70 and the limit price is calculated as $61.60 or $61.70 – the 0.10 limit offset.

Step 3 – Market Rises

As soon as you submit your order, the price of XYZ starts to rise and hits $62.00. The stop price has adjusted accordingly and is at $61.80, or $62.00– the $0.20 trailing amount. Your limit price has also adjusted accordingly and is calculated as $61.70, or 61.80 – the 0.10 limit offset.

Step 4 – Market Price Falls

Suddenly the market price of XYZ drops to $61.90. Your stop price remains at $61.80 and your limit price remains at $61.70, or $61.80 – the 0.10 limit offset.

Step 5 – Market Price Touches Stop Price, Limit Order Submitted

The market price of XYZ continues to drop and touches your stop price of 61.80. A limit order to sell 100 shares of XYZ at 61.70 is submitted to fill at the calculated limit price or better.

Actionable Items

I need to put Trailing stop limit sell order whenever I place an order. I need to start to work on risk management. It is important for me to avoid big loss. 


Project management: Avoid big loss on TFSA account

 Sept. 8, 2020

Introduction

It is important for me to obey the rule. Limit big loss, so I have to learn how to set stop limit order/ trailing order on my TFSA account. 

TFSA Sept 8 2020

This is the biggest loss amount in one day. I tried one thing to sell those stock ENB.TO, PPL.TO, and TRP.TO, and then purchased SU.TO stock, HSE.TO, CVE.TO stocks. But I should set stop order to prevent big loss. 


I should limit the loss less than one thousand dollars/ day. 

Actionable items

I need to put trailing stop limit order on IMO.TO position, CVE.TO position, SU.TO position, HSE.TO position. 

Market risk: Rebound from -3.26% to -2.54% day gain - 9:25 AM

 Sept. 8, 2020

Introduction

It is a tough job to sell those stocks like ENB.TO, TRP.TO, PPL.TO first, and then purchased SU.TO, IMO.TO, HSE.TO, CVE.TO this morning. I like to catch some rebound on those stocks with more than 5% losses. 

9:25 AM status 


As a beginner, I do not know how tough it is to handle market risk, downward turn. All investors learn to sell since they are better than timing the market. I have to take the chance to learn some basics, and see which one has to close true value of stock. 


Market risk: A beginner must learn from her own experience

 Sept. 8, 2020

Introduction

As a beginner, I could not get rid of wishful thinking. I made purchase of Canadian oil stocks on July 31, 2020. My gains are near $3100 dollars. I could not help to reproduce the gains, but I failed on August 24, 2020. I did not set up purchase and I was scared. Now I setup purchase on August 31, 2020. Now market is too hot to go downward. I learn the risk called market risk. 

Market risk

I have to learn how to deal with market risk, and also learn to stay as a long term investor as well. I just learn from those over $3000 losses. The market risk can not be avoided if I choose to stay in the market. 



TFSA: -3.99% -2633.00 gain Day Gain - Total gain -3720.50 (-5.54%)

 Sept. 8, 2020

Introduction

It is dangerous world to invest on stock market. Crude oil is at price of $36.50, -3.72 (-8.72%). The market crashed this morning. I like to document my losses and  what I did. 

Case study

It is hard for me to be a beginner. I learn so many lessons this time since market risk. I did plan to purchase, but I did not know the market risk to go down after August 10% SPX 500 index gains. I have wishful thinking, and this is not working very well on this business world. 





Monday, September 7, 2020

US open: I like to take some time off to watch games

 Sept. 7, 2020

Introduction

It is so excited to see US open 2020 back into play. Professional tennis players can work on competition, even though air bubble plays and no speculators besides. That is so great to watch those high level tennis matches. 



7 Ways to Deal with Uncertainty When Trading

 Here is the link. 

7 ways to deal with uncertainty. http://www.financial-spread-betting.c... PLEASE LIKE AND SHARE THIS VIDEO SO WE CAN DO MORE! Uncertainty is part and parcel of trading - we have to deal with uncertainty all the time. We know we're not guaranteed to win the next trade so there will always be uncertainty. Tips to deal with Uncertainty. 1) Be very clear on your setups. 2) KISS - don't overcomplicate things. 3) Be aware of emotions. 4) Journal all aspects of your trading. If you're uncertain about something write it down and re-examine your decision later. 5) Think in terms of probabilities. This is easier said than done but we know that trading is probabilities game - it is not about the next trade but about the next 50 or 100 trades. 6) Accept you are human. No, we are not robots. 7) Relax and get a life. It is too easy to get caught up...

7 Risk Control Tips from Market Wizards

 Here is the link. 

7 Risk Control Tips from Market Wizards. http://www.financial-spread-betting.c... PLEASE LIKE AND SHARE THIS VIDEO SO WE CAN DO MORE This is a book from the Market Wizards series by Jack Schwager. We have 7 risk control tips from this book; let's look at them and see if we can take some of these ideas and integrate them into our own risk management procedures in our trading. 1) Stop loss points; this is basic stuff, but surprisingly people still trade without stops or managing risk. 2) Reducing the position - if the market is going against you, reduce the position to be less concerned about potential big losses. 3) Selecting low-risk positions - selecting stocks in lower ranges that do not get continually hit with breaking news. 4) Limiting the initial position size - never make a bet you can't afford to lose. Its better to scale into a position or pyramiding up as its working for you. 5) Diversification - the more diversified the holdings the lower the risk. 6) Short selling 7) Hedged strategies - hedging could be buying something that has an inverse correlation to what you're holding or put positions or even a short position. To summarise stop loss orders is the main way to manage risk but it is not the only tool in our armoury - there are other control tips that work in different way to control the risk.


Leetcode discuss: 1104. Path In Zigzag Labelled Binary Tree

 Here is the discussion link. 

Sept. 7, 2020
1104. Path In Zigzag Labelled Binary Tree

Introduction
The problem to find the path from given integer to the root node can be solved using various ways. The easy one I guess can be solved using a few for loops to solve.

My practice
I like to practice the algorithm using a tree algorithm, and also practice the way I think using Stack.
The solution I wrote has "Time Limit Exceeded" bug. But I like to write the solution first, and then learn from my practice.

public class Solution {
    class TreeNode
    {
        public int Val { get; set; }
        public TreeNode left { get; set; }
        public TreeNode right { get; set; }
        public TreeNode(int value)
        {
            Val = value;
        }
    }
    
    public IList<int> PathInZigZagTree(int label) {
        if (label < 1)
            {
                return new List<int>();
            }

            // zigzag traverse the tree level by level, and also build a map
           // with parent node
            var parentMap = new Dictionary<TreeNode, TreeNode>();

            int index = 1;

            // using Queue to apply level by level ordre traversal
            // Tuple<TreeNode, TreeNode> - node, it's parent node
            var stack = new Stack<TreeNode>();
            stack.Push(new TreeNode(index++));

            if(label == 1)
            {
                return new List<int>(new int[] { 1 });
            }
        
            TreeNode found = null;

            while (stack.Count > 0 && index <= label)
            {
                var count = stack.Count;
                var nextLevel = new Stack<TreeNode>(); 

                for (int i = 0; i < count; i++)
                {
                    var root = stack.Pop();

                    // right first, then left
                    for (int j = 0; j < 2; j++)
                    {
                        var child = new TreeNode(index++);

                        nextLevel.Push(child);
                        parentMap.Add(child, root);
                        if (index == label + 1)
                        {
                            found = child;
                        }
                    }
                }

                stack = nextLevel; // maintain the order, do not mix with parent level nodes using standalone stack
            }

            var toRootPath = new Stack<int>();
            while (found != null)
            {
                toRootPath.Push(found.Val);
                if (parentMap.ContainsKey(found))
                {
                    found = parentMap[found];
                }
                else
                {
                    break;
                }
            }

            var list = new List<int>();
            while (toRootPath.Count > 0)
            {
                list.Add(toRootPath.Pop());
            }

            return list;
        }
    }


Overcoming the Fear of Loss (Pulling the Trigger)

 Here is the link. 

Overcoming the Fear of Loss (Pulling the Trigger) http://www.financial-spread-betting.c... PLEASE LIKE AND SHARE THIS VIDEO SO WE CAN DO MORE! Let's assume you have analysed a market and you find a trading opportunity that matches you strategy setup. You are ready to start trading. You hesitate. Will the trade go your way? Will you get it right? FEAR hits you. The other opposite problem is being too aggressive - too willing to trade and keep opening new positions. You can overcome fear by trading with trade sizes that you are comfortable with. Coping with Trading Psychology - Scared of Pulling the Trigger? You’ve heard of the phrase “pulling the trigger”, which means making that fateful step of clicking on the order button and setting the trade in motion. This is something you need to learn to do right if you’re going to trade consistently. Why do so many people get it wrong when they start trading? There are two ways that you can get it wrong, the first is by hesitating, when you’re frozen by fear and so you don’t take the trade in accordance with your strategy; and the second is when you are gun-ho and trading too aggressively, not necessarily waiting for everything to come into line. Looking first at fear, why would this be a problem? After all, if you don’t take the trade your account doesn’t move, and there’ll be another opportunity later. But if you don’t stick with your plan, you won’t build up your experience and more importantly you won’t prove your plan to yourself. In effect, you will be cherry picking your trades in an arbitrary manner and who knows if you will win or lose in the fullness of time? If you have a decent trading plan, it relies on you taking trades consistently in order to guarantee you will win on average over time. Once you start skipping out on trades randomly, you really don’t know if you’re going to win or lose. So if you freeze when all your factors come into line and you know you should place your trade, how do you get around this? It really comes back to a previous lecture where we talked about accepting the risk. When you freeze, you are hesitating to accept the risk of the trade. Quite possibly it means that the amount you could lose is too much for you to be comfortable with. It helps if you can detach yourself from emotion in the money when you’re trading. And one way to do this is to reduce the amount that you face losing for any particular trade. Say you might have lost £1000 taking a trade, but you froze and couldn’t do it. Perhaps you might have placed it if you only risked losing £200. The actual amount is up to you and how you view and value money. You can work on this by going back to a smaller stake for your trades, and building back up over time. It can help to step up the amount incrementally. The other way to approach it is to work harder on detachment from the money itself. You’ve set it to one side, away from your money you use for rent and food, and now it is play money. Think of it like Monopoly money, interesting but not carrying your emotions and fear of loss. This is a very difficult thing to do for some people, but if you can achieve it, it will make you a far better trader, more able to contain your emotions and trade rationally.

Stock market: Labor day and zero sum game discussion

 Here is the link. 


TESLA - do not join SP 500 Index - too many retail investors - 400 billion, not accepted by SP 500 index

Zero sum game - discussion, very good teaching 



Scaling into Positions

 Here is the article. 



Strategy: Tactics for Scaling Out of Trades

 Here is the link. 

Scaling Out of Trades. http://www.financial-spread-betting.c... PLEASE LIKE AND SHARE THIS VIDEO SO WE CAN DO MORE! Whenever traders gather together, there will be talk about whether it is a good thing to scale in and/or out of trades. This is a matter of personal preference, and you must make up your own mind whether you think it’s a good practice – on the face of it, there are good arguments why you should not need to do this and may even be leaving money on the table if you choose to scale. But there are more factors to trading than simple mechanics. One of the most important factors in trading is your own psychology, how you feel about your trade and how that affects what you do. If you have done much trading, you will know how emotions can affect you and cause you to make wrong decisions. The fact is that our natural reactions are often the exact opposite of what we need when trading. This is why scaling out of trading can nurse you along and make a better trader of you. Consider the following situation. You see an uptrend forming, and consider it is worth making a trade. The uptrend may be a small one, or it may involve several phases as discussed in a previous lecture. You calculate your stop loss position, and your maximum loss from the trade, and hence decide how much to place at risk. If it fails, that’s it and you’re out at your stop loss, which is all part of the game. If it succeeds, the price increases until it settles at a level from which it may pull back a little before resuming. You consider taking your profit now. If you do, you have the instant satisfaction of knowing you have made a gain. But if you were to close the trade completely, you might be worried that you were going to miss a further gain after the pullback. If you only take out part of the trade, say a half, you can get the emotional high of having made a win, and also avoid some of the worry that you are missing out on any potential future gain. You reset your stop loss level, and continue to follow the trade. If the pullback continues and pushes the price down, the trade is closed out on the stop loss, and you have the satisfaction of knowing that you made a good profit on your first half, and still held on to some of the profit from the second half. If the price goes back up with another push, then you stand to make more money on the part of your stake that you left in the trade, another reason for self-congratulation! You can repeat this process at each pullback level, getting the emotional high of making more profit and looking it in, without the worry that you have lost any chance of making more from the trade. It’s easy to see that making the trade this way is far more satisfying and rewarding emotionally than a straight in and out, and that’s why this lesson suggests that you consider scaling out of your trades, where appropriate.

How to use the Risk Reward Ratio And Probability

 Here is the link.