Sunday, October 25, 2020

America's Looming Eviction Crisis

 Here is the link. 

10 million people lost their homes in the wake of the 2008 crash. What we're about to experience will be much worse. Thanks to a combination of COVID, the cult of capitalism, and America's horrific pandemic response, 28 million renters are facing eviction. And that's not even counting those who own their homes. We're in for a housing crisis of unprecedented magnitude.


4:44/ 11:29

110 million American renters

20% face eviction


Out of work and facing an eviction

 Here is the link. 

W9 form

$11,752 court fee and rulings 

2,300 dollars to pay for it. 

Eviction note - follow laws here for the change 

Leetcode discuss: 1631. Path With Minimum Effort

Here is the link on youtube.com. 



Here is my Leetcode discuss post.

First practice - C# copy idea and copy code to learn quickly

Oct. 25, 2020
Introduction
It is the third algorithm in weekly contest 212. I started the contest late and only had 10 minutes left, I thought about the problem and it was hard. I could not find a working idea.

After the contest
I just quickly went over the discussion post, and then I like to study the code and then figure out the following:

  1. Start from top left node in the matrix, define C# Tuple<int, int,int>(int Height, int row, int col);
  2. Try to start from top left node to visit all nodes in the matrix, but choose the order to get minimum distance. How to do that? Design a minimum heap.
  3. Define a minimum heap with distance, and always remove the minimum node from the heap, and then visit it's unvisited neighbors, and add all those neighbors to the heap.
  4. Make sure that visit all nodes in the order based on minimum distance until bottom right node is reached.
  5. Define a node with distance based on consideration of previous node's distance in minimum heap process and current one.

Case study
I think that the code is pretty standard minimum heap practice once I understand the idea and learn how to reason it.

I need to look into C# SortedSet default comparer for this Tuple<int, int, int>. It is surprising that the code can be simplified using short hand expression, and no need to write any code related to IComparer as well. I did look up Google.

It is much better to work on a small case study, then I can quickly understand the algorithm and how to design it next time.

Example:
Matrix
1, 2, 3
3, 8, 2
5, 3, 5
Using A, B, C, D, E to mark those first five nodes in matrix.
1A, 2B, 3C
3D, 8E, 2
5, 3, 5
Add A node in matrix into minimum heap, (0,0,0), remove minimum one in the heap, and then visit A's neighbor nodes B and D, and then add B and D into minimum heap.
Next step is to remove minimum node in the heap, which is B. The distance is 1, and add C and E into the heap.

Step by step
Let me work on a more simple example,
Example:
Matrix
1, 2
3, 8
Add A, B, C, D marks to simplify the explanation.
1A, 2B
3C, 8D
1A is added to minimum heap, the minimum effort is 0;
remove 1A from minimum heap, and visit two neighbors, 2B and 3C.
1A -> 2B has minimum effort 1, and 1A to 3C has minimum effort 2.

Add 2B and 3C to minimum heap. The smallest one is 2B.

Next is to remove 3B from minimum heap, visit 2B's neighbor 8D, so 8D has minimum effort 6. Add (6, 1, 1) to minimum heap.

Next is to remove 3C from minimum heap, visit 3C's neighbor 8D, so 8D has minimum effort 5. Add (5, 1, 1) to minimum heap.

The tip is to mark visit only after the node is popped from minimum heap. In our simple example case, 8D has chance to be added into minimum heap more than once, first one is with height 6, second one is with height 5.

Since minimum heap is sorted, the path from 1A->3C->8D is removed from minimum heap first before 1A->2B->8D, the answer is 5 not 6.

In summary, the first tip is enforce order using minimum heap, and the second tip is to mark visit after the node is removed from minimum heap, so one node 8D has two chance to be considered and added to minimum heap. It is kind of clever. But it took me over 30 minutes to figure out, I had to debug the code using Visual studo first, and then figure out step by step.

Go over again, the minimum heap step by step:

  1. 1A, (0, 0, 0)
  2. remove 1A from heap, add 2B and 3C, sort them.
    (1, 0, 1)
    (2, 1, 0)
  3. remove 2B from minimum heap, add 8D into minimum heap.
    (2, 1, 0)
    (6, 1, 1)
  4. remove 3C from minimum heap, add 8D into minimum heap.
    (6, 1, 1)
    (5, 1, 1)
    sort them
    (5, 1, 1)
    (6, 1, 1)
    Remove 8D from minimum heap, which is bottom right, minimum effort is 5, not 6. The path is from 1A -> 3C -> 8D.

I do believe if I can read this short case study, then I can write the code in the contest or phone screen in 10 minutes. But I have to go over step by step to understand competition of two 8D entries in minimum heap in order to get minimum effort.

public class Solution {
        // (0,1),(1,0),(0,-1), (-1,0) four directions, simplified version
        private int[] directions = new int[] { 0, 1, 0, -1, 0 };
    
        /// Oct. 25, 2020
        /// study code: 
        public int MinimumEffortPath(int[][] heights)
        {
            int r = heights.Length;
            int c = heights[0].Length;
            bool[,] visited = new bool[r,c];
            
            // declare Tuple data type
            // https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/types
            // new Tuple<int,int,int>( int H, int X, int Y) -> short hand -> (int H, int X, int Y)
            // default comparer ? 
            var sorted = new SortedSet<(int H, int X, int Y)>();
            
            sorted.Add((0, 0, 0)); 
            while (sorted.Count > 0)
            {
                // find smallest one in Height, if the same, then compare X, then compare Y
                // ask why? What is strategy? Find smallest one - greedy 
                // 
                var cur = sorted.Min;
                
                if (cur.X == r - 1 && cur.Y == c - 1)
                {
                    return cur.H;
                }
                
                visited[cur.X, cur.Y] = true;
                
                // Look up C# SortedSet source code - Remove API
                // very complicated - red black tree - find node and remove node
                // https://referencesource.microsoft.com/#system/compmod/system/collections/generic/sortedset.cs
                sorted.Remove(cur);
                
                for (int d = 0; d < 4; d++)
                {
                    int nx = cur.X + directions[d];
                    int ny = cur.Y + directions[d + 1];
                    
                    if(nx < 0 || nx == r || ny < 0 || ny == c || visited[nx,ny]) 
                    {
						continue;
                    }
                   
                    // all nodes in smallest path - smallest distance should be maximum one
                    var next = Math.Max(cur.H, Math.Abs(heights[cur.X][cur.Y] - heights[nx][ny]));
                    
                    sorted.Add((next,nx,ny));
                }
            }

            return 0;
        }
}

After mock interview
10/25/2020 3:58 PM 

I could not make it work in my mock interview as an interviewer, then I debugged the code using visual studio, and learned the detail the competition case in minimum heap. 

I recorded another video. 

Saturday, October 24, 2020

My business school - my MBA - How Robinhood Makes Money

 Here is the link. 

Robinhood, an investing app valued at over $5 billion, says it's trying to "democratize America's financial system" by making investing accessible to the little guy with free trades. It's an eye-popping valuation for a financial company with opaque metrics and plenty of competition. The young company had its share of missteps as well, prompting questions of whether or not it can handle primetime. Robinhood has faced criticism for business practices that allow it to offer free trading. It also botched the rollout of a checking and savings account feature in late 2018, garnering concern from regulators. But the company's incredible growth and popularity with younger investors – more than 6 million users by the end of 2018 – means it could be a major player in banking moving forward. » Subscribe to CNBC: http://cnb.cx/SubscribeCNBC


My business school - My MBA : How Venmo Makes Money

 Here is the link. 

Venmo has revolutionized the way pay each other back. From sending roommates the rent check to reimbursing friends for dinner, people ‘Venmo’ each other all the time. But have you ever wondered how this fun, emoji laden payments app actually makes money? Well, for years, it hasn’t. But now Venmo is on the cusp of profitability for its parent company, Paypal. Concerns remain about privacy for users and security for their money. And many on Wall Street are still waiting to see whether this millennial digital payments phenomenon is just flash in the pan or if it’s really here to stay. Bill Ready, Paypal's COO and the man who brought the once no name app to mainstream fame invited CNBC to Venmo's New York offices to get a look inside how the payment app works. NOTE: On April 24, 2019 (a day after this video was published), PayPal revealed for the first time that Venmo has 40 million users. In the video above, CNBC cited eMarketer, which had estimated 27.4 million Venmo users as of April 2018.. In its first-quarter 2019 earnings report, PayPal said it now has a total 277 million total customer accounts — including 22 million merchant accounts. Total payments volume for Venmo grew 73 percent year over year to $21 billion in the first quarter, the company said. The company said Venmo is still on pace to do $100 billion in payment volume this year.



Small business owner: Things I learned from dentist office - two visits

 Oct. 24, 2020

Introduction

I was in financial struggle, and I had four big teeth extracted, three of them was extracted in January 2019, but I could not afford to have any implant. Each one will cost me $4500 in the city of Vancouver. I recently visited twice since my dental insurance will expire in October. I had $1000 dollar budget to spend to get service. 

Small dentist office near rupert/ kingsway

I visited dentist office for a few years starting from 2010, and then I moved to dentist office in metro town. But I figured out that I lost three big teeth, and I learned lessons to be educated. I never can learn things so hard to have three teeth infected all the time. I experienced the bone loss, gum surgery, infection. I should extract one tooth early to save neighbor tooth. 

Small dentist office

The dentist does so many things for various customers. He can do normal cleaning, and any other dental jobs if needed. The office used square a few years ago. I just learned that the box is called square. My friend Rick bought Square stock and made 100% return this year. I was naive to bet on hotel, airline stock etc. 




Business school - My MBA: How Square Makes Money

 Here is the link. 

Square began in 2010 after the invention of a small credit card reader that plugged into iPhones. About 10 years later, the company has grown into a $26 billion fintech behemoth under Jack Dorsey's leadership. Square profits off a lot more than card swipes at your favorite trendy coffee shop. The company provides a wide range of software products for sellers that helps simplify everything from payroll to making appointments with customers. Square offers small business loans as well, often in sums smaller than traditional banks are willing to lend to neighborhood stores, restaurants and coffee shops. On the consumer side, Square launched Cash App, originally called Square Cash, in 2013. Since then, the app has seen enormous growth, jumping from 7 million to 15 million users in 2018 alone. Square credits its success to a mission of economic empowerment for everyone from a small business owner to a major retailer. But critics say the company may have lost focus, be overvalued, and struggle to sustain growth if the U.S. faces an economic downturn. » Subscribe to CNBC: https://cnb.cx/SubscribeCNBC


50,000 readers/ payment volume 

2.75% + 0.15 

$15 billion/ year -Jack Dorsey -, CEO, Square & Twitter 


America In Crisis: Economic Turning Point | NBC News

 Here is the link. 

NBC’s Stephanie Ruhle, CNBC’s Wilfred Frost, and Telemundo’s Jose Diaz Balart anchor an hour of coverage tied to the economic crisis that’s hitting millions of Americans because of the pandemic. They’ll be joined by newsmakers and real Americans feeling the impact personally.

Unemployed fighting to stay afloat as extended COVID-19 benefits remain in limbo

 Here is the link. 

Some argue the weekly $600 unemployment payment was too much, keeping people from going back to work. Meanwhile, with some industries unable to return to work, people try to make ends meet.

13339 102A AVENUE 313, Surrey, British Columbia V3T0C5

 $308,000

I still remember that I went to see new model home over 10 years ago. The price was around $130,000 dollars. I just could not believe that I chose not to purchase one, get mortgage. Now the price is still double, coronavirus crisis will affect millions people's job, and million people will be evicted as renters. 

I like to wait and see what is next. Market should go down more. 

Property Summary for 13339 102A AVENUE

Type
 
Single Family
Sub-Type
 
Strata
Building Type
 
Apartment
Title
 
Strata
MLS® Number
 
R2511398
Year Built
 
2009
Stories
 
1
Basement
 
None
Neighborhood
 
Surrey City Center
Postal Code
 
V3T0C5

Friday, October 23, 2020

SU.TO stock: 10% gains from Oct. 22 to Oct. 23, lowest: 15.07, highest 16.5

 Oct. 23, 2020 

Introduction

I like to push myself to do better equity research, so that I should take action to purchase 3000 shares of Su.to when the price was around $15.07 on Oct. 22, 2020, so that I have chance to have gains. Since the price was lowest one in 2020. I like to write a blog to help me do better research. 

10% gains

I should not bet on short term gains in two days for 10%. What I should do is to stay positive, buy low and sell high. If I do believe that it is lowest price, then I should not be afraid to purchase 1000 shares of SU.TO stock. 

I should not worry about market price goes down more since I can be a long term investor. 



I should not worry too much. I sold 550 shares on Oct. 23, 2020 with 20 cents/ share gain for 500 share. That is only 100 dollars. 

I lost $8000 in Sept. 2020 since I purchased so many oil stocks. I should take some risk and bet on rebound. 



Leetcode algorithms: Seven ideas to go over hard level algorithms

 Oct. 23, 2020

Introduction

It is challenge for me to figure out how to advance my problem solving skills on Leetcode.com. I like to figure out something for short term benefits. 

I will write more later. 

I like to read more about topics. Here is the page. 

Important and useful links on Leetcode.com - Here is the link. 


C# ICollection interface: Source code

I plan to spend more time to read C# source code about IList, ICollection, IEnumerable, List, Array, and Char class. 

I did not notice that ICollection is different from IEnumerable interface. Here are all functions inside ICollection. 



SU.TO stock: What is most important to make business decision?

 Oct. 23, 2020

Introduction

I reflected my decision to purchase SU.TO stock 500 shares, and I did buy and sell three times and only made less than $400 dollars. But my analysis told me that I should purchase 3000 share at lowest price Oct. 12 at $15.07. How to tell what makes good trade as a beginner. 

I like to talk about a few things, Do not be afraid, think independently, take a small test, and be bold, ready to hold long term, and take some adventure. 

It is hard for me to train myself from a gambler to a smart investor. I like to write down the journey. 


Speculation: More optimistic - SU.TO stock

 Oct. 23, 2020

I just could not believe that I sold 500 shares of SU.TO too early, and I did not catch full 6.0% gains on those shares. 


I sold 550 shares of SU.TO too early, since I did not catch the gains from 15.58 to 16.07, those 49 cents/ share. 

I also need to think about more betting on more shares. I think that SU.TO has lowest price in last 12 months. 

I like to reduce my risk by setting my goal of gains monthly to $500 dollars, so I can reduce risk to lose my capital. 

It does not matter how good I think I know stocks I purchase, market risk is so hard to get rid of. I am still gambling with my own capital. I need to learn to be patient, build my gains first and then use those gains to invest on stock market. 


Thursday, October 22, 2020

Market risk: Take it easy, stay calm - missing 23.63% rebound on SABR from Sept 25, 2020 to Oct. 22, 2020

 




Vision Critical: Vision Critical Continues Transformation to CXM Leader with New CEO and President of Products

 Here is the article. 

I like to learn more about Vision Critical. 

“I’m excited to partner with the leadership team and the board as we continue to move Vision Critical forward in the CXM market,” said Raihan, who will lead product strategy, product management, research & development, engineering, UX design and customer cloud operations for the company. “Both Ross and I look forward to galvanizing employees to drive world-class execution and build a customer-centric culture that is based on growth and a winning environment.”

Raihan has over 20 years of technology and product leadership experience in the United States and Canada. He is a veteran of SAP, Cisco, Infor, and Accenture. He comes to Vision Critical from Cisco where he served as the Global GM for the Internet of Things (IoT) business unit. He led a team of 1,200 engineers, architects and product managers that made digital strategies come to life by harnessing the power of IoT, cloud, analytics and AI/machine learning. Prior to joining Cisco, Raihan spent a decade with SAP. As Senior Vice President & COO at SAP, Raihan was responsible for product operations, value engineering, solution engineering, industry products and centers of excellence.

About Vision Critical

Vision Critical is a cloud-based CXM SaaS company that specializes in gathering and applying the hardest-to-reach customer experience data. Using proprietary technology and processes, Vision Critical is able to deeply engage any audience to increase voluntary customer data capture and apply that data to improve customer experience. With its unique, relationship-based approach, Vision Critical’s Sparq platform enables companies to interact directly with consented audiences of customers. Unlike traditional voice-of-customer methods, Vision Critical unlocks the real-time feedback that companies need to build better products, deliver better services and achieve better business outcomes hand in hand with their own highly engaged, deeply understood customers.


Wednesday, October 21, 2020

SU.TO stock: credit rating BBB+, 5.4% yield

 All stocks related to oil and gas have done poorly this year. The lower energy demand due to the pandemic impacts weighed on oil and gas prices. Even integrated oil majors like Suncor did not get exempt from the downdraft. The stock is down 63% year to date.

An economic recovery resulting in normal energy usage will drive steady growth of energy demand. This will cause Suncor stock to trade much higher. Buffett is probably counting on that swing to the upside when energy prices recover.

Suncor is a diversified large-cap company that has staying power. Its financial position remains solid and is awarded an investment-grade S&P credit rating of BBB+. Currently, it also pays a 5.4% yield.

Analysts have an average 12-month price target of $29.40 on Suncor stock, which represents a whopping near-term upside potential of almost 88%.

Leetcode discuss: 472. Concatenated Words

 Here is the discussion post. 

C# break into hashSet + DP problem

Oct. 20, 2020
472. Concatenated Words
Introduction
It is a hard level algorithm. I like to practice and also like to simplify the practice with an easy solution.

Case study
I like to choose one of Leetcode discussion posts to study, and write a simple test case. My goal is to write code to make this case work.

Assuming that words are the following three words:
{"cat","dog","catdog"}, my task is to prove that "catdog" can be break into "cat" and "dog". I also like to using dynamic programming solution to solve it.

catdog
012345
Declare dp array with size 7, dp[7] since "catdog"'s length is 6.
dp[6] = true, in other words, "catdog" is in original hashSet.
dp[3] is true since "dog" is in hashSet and dp[6] is true;
dp[0] is true since "cat" is in hashSet and dp[3] is true.

I am not sure how this dynamic programming is designed orginally. I just quickly studied and will come back with more ideas to write down.

Time complexity
Will be added very soon.

Advice
Plan to review 139 Word break I and 140 Word break II.

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

namespace _472_ConcatenatedWords
{
    class Program
    {
        static void Main(string[] args)
        {
        }

        /// <summary>
        /// Leetcode 472 - 
        /// Review my own practice first
        /// 139 Word break I
        /// 140 Word break II
        /// And then work on Leetcode 472 - Concatenated words
        /// study code
        /// https://leetcode.com/problems/concatenated-words/discuss/347648/C-HashSet-%2B-WordBreak
        /// </summary>
        /// <param name="words"></param>
        /// <returns></returns>
        public IList<string> FindAllConcatenatedWordsInADict(string[] words)
        {
            var result = new List<string>();
            if (words.Length <= 2)
            {
                return result;
            }

            var hashSet = new HashSet<string>(words);
            foreach (var word in words)
            {
                if (word == "")
                {
                    continue;
                }

                hashSet.Remove(word);

                var canBreak = WordBreak(word, hashSet);

                if (canBreak)
                {
                    result.Add(word);
                }

                hashSet.Add(word);
            }

            return result;
        }

        /// <summary>
        /// case study: 
        /// hashSet = {"cat","dog","catdog"} - remove catdog from hashSet before calling
        /// s = "catdog"
        /// dp = new bool[7];
        /// dp[6] = true; // "catdog" is in hashSet
        /// index = 3, s.Substring(3) is "dog" which is in hashSet. 
        /// dp[6] == true, s.Substring(3, 3) == "dog", j == 5
        /// so dp[3] = true
        /// likewise dp[0] = true since dp[3] = true, and s.Substring(0,3) = "cat", and "cat" is 
        /// hashSet.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="hashSet"></param>
        /// <returns></returns>
        private bool WordBreak(string s, HashSet<string> hashSet)
        {
            if (s.Length == 0)
            {
                return false;
            }

            var n = s.Length;
            var dp = new bool[n + 1];
            dp[n] = true;

            for (int i = n - 1; i >= 0; --i)
            {
                for (int j = i; j < n; ++j)
                {
                    if (dp[j + 1] && hashSet.Contains(s.Substring(i, j - i + 1)))
                    {
                        dp[i] = true;
                        break;
                    }
                }
            }

            return dp[0];
        }
    }
}

Leetcode discuss: 140. Word Break II

 Here is my discussion post. 

C# 2020 Oct 20 warmup practice using DFS + memoization

Oct. 20, 2020
140. Word Break II
Introduction
What is the best way to master a DFS + memoization algorithm? I like to take 30 minutes to warmup this hard level algorithm.

Case study
I do think that it is best investment of time to work on a simple test case, and then go over the detail how to solve the problem.
Given a string "catsanddog", and a dictionary with the following words:
{ "cat", "cats", "and", "sand", "dog" }, find all possible word breaks.
There are two answers:
"cat sand dog" and "cats and dog".

Run depth first search, and also memoize the intermediate string with words to construct, here are hashMap with the following entries with the order:

  1. key = "dog", value = "dog";
  2. key = "sanddog", value = "sand dog";
  3. key= "anddog", value = "and dog";
  4. key = "catsanddog", value is list of two strings, "cat sand dog" and "cats and dog".

The hashMap is used once for string "dog" to look up, and return a linked list directly.

First, go over all the words one by one, first one is "cat", and then run depth first search, next one is "sand" and then "dog" is last, and "" is searched as base case.

C# LinkedList - IEnumerable
It is also the good practice to see how to write LinkedList based on interface IEnumerable.

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

namespace _140_word_break_II___Oct_20
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = "catsanddog";
            var wordDict = new string[] { "cat", "cats", "and", "sand", "dog" };

            var result = WordBreak(s, wordDict);

            /// cats and dog
            /// cat sand dog
            Debug.Assert(result[0].CompareTo("cat sand dog") == 0);
            Debug.Assert(result[1].CompareTo("cats and dog") == 0);
        }

        /// <summary>
        /// code review on Oct. 20, 2020
        /// </summary>
        /// <param name="s"></param>
        /// <param name="wordDict"></param>
        /// <returns></returns>
        public static IList<string> WordBreak(string s, IList<string> wordDict)
        {
            return runDFS(s, wordDict, new Dictionary<string, LinkedList<string>>());
        }
        
        /// <summary>
        /// "catsanddog"
        /// words = {"cat","cats","and","sand","dog"}
        /// cats and dog
        /// cat sand dog
        /// </summary>
        /// <param name="s"></param>
        /// <param name="wordDict"></param>
        /// <param name="map"></param>
        /// <returns></returns>
        private static IList<string> runDFS(string s, IList<string> wordDict, Dictionary<string, LinkedList<String>> map)
        {
            // Look up cache 
            if (map.ContainsKey(s))
            {
                return map[s].ToList();
            }

            var list = new LinkedList<String>();

            // base case 
            if (s.Length == 0)
            {
                list.AddLast("");
                return list.ToList();
            }

            // go over each word in dictionary
            foreach (string word in wordDict)
            {
                // C# string.StartsWith API
                if (s.StartsWith(word))
                {
                    var nextList = runDFS(s.Substring(word.Length), wordDict, map);

                    foreach (string sub in nextList)
                    {
                        list.AddLast(word + (string.IsNullOrEmpty(sub) ? "" : " ") + sub);
                    }
                }
            }

            // memoization
            map.Add(s, list);

            return list.ToList();
        }
    }
}