Tuesday, December 29, 2020

Leetcode discuss: 438. Find All Anagrams in a String

 Here is the link. 

Second practice - C# - Linear time - Counting sort

Dec. 29, 2020
Introduction
My first practice ran into time out problem since the sorting is applied. I read the problem statement again and then decide to use counting sort with linear time, the problem is solved.

Edge case
I ran into the wrong answer, so that I figured out that extra checking is needed in the function isAnagram.

if(count[item - 'a'] < 1 )
{
    return false; 
}

20 days break

I just took 20 days break after Dec. 8. It is surprising to learn from my two mistakes I had in my practice.

public class Solution {
    public IList<int> FindAnagrams(string s, string p) {
        if(s == null || p == null || s.Length == 0 || p.Length == 0 || s.Length < p.Length)
            return new List<int>(); 
        
        var sLength = s.Length; 
        var pLength = p.Length; 
        
        var list = new List<int>();                                   
        
        for(int i = 0; i < sLength && i + pLength <= sLength; i++)
        {
            var substring = s.Substring(i, pLength);
                        
            if(isAnagram(substring, p))
            {
                list.Add(i);
            }
        }
        
        return list; 
    }
    
    private bool isAnagram(string s, string t)
    {
        var count = new int[26];
        foreach(var item in s)
        {
            count[item - 'a']++;
        }
        
        foreach(var item in t)
        {
            if(count[item - 'a'] < 1 )
            {
                return false; 
            }
            
            count[item - 'a']--;
        }
        
        return count.Sum() == 0;         
    }
}

Leetcode discuss: 438. Find All Anagrams in a String

 Here is the link. 

TLE error - C# - First try - Reading skills

Dec. 29, 2020
Introduction
It is important to train myself to read very well. There is timeout issue if O(NlogN) sorting algorithm is applied to a string.

The string is given with the constaint "Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.". It can take O(N) time to determine if a string is anagram of another string. N is 20,100, NlgN will be around 80,000. This should be a warning number to avoid timeout.

The following code has TLE problem. This is my first try in my mock interview on premium version.

Time complexity:
O(N*M*logM), N is length of string s, M is length of P
The solution is not working, the time complexity should be O(N*M).

public class Solution {
    public IList<int> FindAnagrams(string s, string p) {
        if(s == null || p == null || s.Length == 0 || p.Length == 0 || s.Length < p.Length)
            return new List<int>(); 
        
        var sLength = s.Length; 
        var pLength = p.Length; 
        
        var list = new List<int>(); 
        
        if(sLength == pLength && s.CompareTo(p) == 0)
        {
            list.Add(0);
            return list; 
        }        
        
        var pArray = p.ToCharArray();
        Array.Sort(pArray);
        var sortedP = new string(pArray); 
        
        var found = new HashSet<string>(); 
        
        for(int i = 0; i < sLength && i + pLength <= sLength; i++)
        {
            var substring = s.Substring(i, pLength);
            var addToList = false; 
            if(found.Contains(substring))
            {
                addToList = true; 
            }
            else
            {                
                var array = substring.ToCharArray();                
                Array.Sort(array);
            
                var sorted = new string(array);
                if(sorted.CompareTo(sortedP) == 0)
                {
                    addToList = true;                    
                }
            }
            
            if(addToList)
            {
                 list.Add(i);
                 found.Add(substring); 
            }
        }
        
        return list; 
    }
}

Leetcode discuss: 416. Partition Equal Subset Sum

 Here is the link. 

Second practice - C# - Next round - avoid adding more than once

Dec. 29, 2020
Introduction
I wrote a solution but failed at next to last test case. I debugged the code and then figured out that same number in the array is added more than once. After my first failed practice, I started to work on bug fix.

Failed test case
var test = new int[] { 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20, 20, 24, 24, 24, 24, 24, 24, 24, 24, 28, 28, 28, 28, 28, 28, 28, 28, 32, 32, 32, 32, 32, 32, 32, 32, 36, 36, 36, 36, 36, 36, 36, 36, 40, 40, 40, 40, 40, 40, 40, 40, 44, 44, 44, 44, 44, 44, 44, 44, 48, 48, 48, 48, 48, 48, 48, 48, 52, 52, 52, 52, 52, 52, 52, 52, 56, 56, 56, 56, 56, 56, 56, 56, 60, 60, 60, 60, 60, 60, 60, 60, 64, 64, 64, 64, 64, 64, 64, 64, 68, 68, 68, 68, 68, 68, 68, 68, 72, 72, 72, 72, 72, 72, 72, 72, 76, 76, 76, 76, 76, 76, 76, 76, 80, 80, 80, 80, 80, 80, 80, 80, 84, 84, 84, 84, 84, 84, 84, 84, 88, 88, 88, 88, 88, 88, 88, 88, 92, 92, 92, 92, 92, 92, 92, 92, 96, 96, 96, 96, 96, 96, 96, 96, 97, 99 };

Working solution
I made the code change, use HashSet to store the new updated value first, and then update dp[] array in the last.

public class Solution {
     public  bool CanPartition(int[] nums) {
            if(nums == null || nums.Length == 0)
                return false; 
        
            var length = nums.Length; 
            var sum = nums.Sum(); 
        
            if(sum % 2 == 1)
                return false; 
            var target = sum / 2; 
        
            var dp = new bool[sum + 1]; // target + 1 optimal
        
            //Array.Sort(nums);

            var prefixSum = 0; 
            for(int i = 0; i < nums.Length; i++)
            {
                var current = nums[i];

                // hard to figure out - only add once - this bug 
                var nextRound = new HashSet<int>(); 
                for (int j = 1; j <= prefixSum; j++)
                {
                    if (dp[j])
                    {
                        nextRound.Add(j + current); 
                    }
                }

                foreach (var item in nextRound)
                {
                    dp[item] = true; 
                }

                dp[current] = true;

                prefixSum += current;

                if (dp[target])
                    return true; 
            }

            return dp[target];
        }
}


Leetcode discuss: 416. Partition Equal Subset Sum

 Here is the link. 

Mock interview - C# - Hard to tell - add number more than once - Failed 114/115

Dec. 29, 2020
Introduction
I wrote the solution in Leetcode premium mock interview onsite from Facebook, I could not pass the test case 114/115. But I could not tell what it is wrong.

Failed test case
var test = new int[] { 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20, 20, 24, 24, 24, 24, 24, 24, 24, 24, 28, 28, 28, 28, 28, 28, 28, 28, 32, 32, 32, 32, 32, 32, 32, 32, 36, 36, 36, 36, 36, 36, 36, 36, 40, 40, 40, 40, 40, 40, 40, 40, 44, 44, 44, 44, 44, 44, 44, 44, 48, 48, 48, 48, 48, 48, 48, 48, 52, 52, 52, 52, 52, 52, 52, 52, 56, 56, 56, 56, 56, 56, 56, 56, 60, 60, 60, 60, 60, 60, 60, 60, 64, 64, 64, 64, 64, 64, 64, 64, 68, 68, 68, 68, 68, 68, 68, 68, 72, 72, 72, 72, 72, 72, 72, 72, 76, 76, 76, 76, 76, 76, 76, 76, 80, 80, 80, 80, 80, 80, 80, 80, 84, 84, 84, 84, 84, 84, 84, 84, 88, 88, 88, 88, 88, 88, 88, 88, 92, 92, 92, 92, 92, 92, 92, 92, 96, 96, 96, 96, 96, 96, 96, 96, 97, 99 };

Hard to tell
Every time the number is considered, it is important to avoid the number to be added more than once.

For example, [1, 7, 4, 5],
dp[1] = true, since first number 1 is in the array;
dp[7] = true, since 7 is the second number in the array;
Also dp[8] should be true, since 1 + 7 = 8.
Next it is to work on index = 2, value 4,
dp[5] should be true, since 1 + 4 = 5, but it should not be updated right away.
The for loop in the following code is to iterate from 1 to 8.
Avoid setting dp[5 + 4] = 9.

Let me try to explain what it is wrong in the following statements:

for (int j = 1; j <= prefixSum; j++)
{
	if (dp[j])
    {
        dp[j + current] = true; 
    }
}

The reason to set dp[9] = true is that dp[5] is set true right away, and then dp[5] + 4 = 9, but 4 is counted twice.

The following code has a bug but I could not tell in my mock interview. I spent over 5 minutes to think but failed to come out the idea.

The correct solution
The working solution is here.

The following code has a bug, could not pass online judge. But I like to remind myself to be humble, and will figure out how to avoid the bug quickly.

public class Solution {
     public bool CanPartition(int[] nums) {
            if(nums == null || nums.Length == 0)
                return false; 
        
            var length = nums.Length; 
            var sum = nums.Sum(); 
        
            if(sum % 2 == 1)                
                return false; 
         
            var target = sum / 2; 
        
            var dp = new bool[sum + 1]; // target + 1 optimal
        
            Array.Sort(nums);            

            var prefixSum = 0; 
            for(int i = 0; i < nums.Length; i++)
            {
                var current = nums[i];                

                for (int j = 1; j <= prefixSum; j++)
                {
                    if (dp[j])
                    {
                        dp[j + current] = true; 
                    }
                }

                dp[current] = true;
                
                prefixSum += current;

                if (dp[target])
                    return true; 
            }

            return dp[target];
        }
}

AC stock: Raise more money

 Dec. 29, 2020

Air Canada is raising more money

On December 15, the largest Canadian airline revealed its plan to raise more money with a share offering. With this offering, the struggling airline plans to raise about $850 million to supplement its working capital and other cash needs. It also expects that the money raised with these offerings will help the company improve its cash position and allow it to implement recovery measures in the near future.

Air Canada has already lost nearly $2.8 billion in the first three quarters of 2020. The analysts expect the airline to add another slightly less than $1 billion to its 2020 losses in the fourth quarter.

In its latest press release, the company highlighted it’s burning $14 million to $16 million cash each day on an average in Q4. Previously, during its third-quarter earnings event, it gave a much lower cash burn projection range of $12 million to $14 million per day for the fourth quarter.

These factors clearly reflect how the situation seems to be getting more worrisome for Air Canada.

Case study: Swing trade | INTC Dec 16-21 6 - 12% drop | Microsoft - Cloud - chip | Dec 29 4.9% gains

 Dec. 29, 2020

Introduction

It is the idea for me to look into. I should consider to work on a swing trade, bet on INTC stock under value, purchase 500 shares instead of 5 shares on Dec. 24. How to design a swing trade on INTC stock, why?

INTC stock


84 million shares, price at $49/ share, total transaction is around $4.2 billion US dollars. It is definitely a good place for a retail player to bet on short term return. 


Dec 22, 2020

I purchase 10 shares of INTC stock on Dec. 22, 2020. I should consider INTC is under value. The market is not rational on Microsoft news on cloud solution to manufacture it's own chip. 

I should invest using TFSA account, purchase 500 shares of INTC. 

Yahoo finance


I should consider short term or long term investment. So I should invest 500 shares at price $45.99. 

INTC stock

Take some time to learn undervalued stocks, INTC is the best stock for me to work on as a value investor. 


Expr stock: Yahoo -> finance -> conversation

 Comment: 

 EXPR has 6 months from the Sep notice. They’ve met one of 2 criteria to regain compliance so far. On the last calendar day (Thursday 12/31), they need an average of 1.00+ over 30 trading days and a price over 1.00. They’re looking really good on the first point (average). They just need to close above $1.00 on Thursday and they can regain compliance...early.



Monday, December 28, 2020

Evictions Are Violence: Millions Could Lose Homes Amid COVID Pandemic If Federal Moratorium Expires

 Here is the link. 

Millions across the U.S. could be forced from their homes in the middle of the pandemic if Congress does not extend the federal eviction moratorium that is due to expire at the end of December. Congress is expected to push the moratorium back by one month, to January 31, in the $900 billion stimulus bill being debated in Washington, but such an extension would only be a temporary fix to a much wider problem. The U.S. Census Bureau reports that one-third of U.S. households are behind on rent or mortgage payments and will likely face eviction or foreclosure in the next two months. We speak with UCLA researcher Kathryn Leifheit, who says the lifting of state eviction moratoriums this summer led to 430,000 new COVID infections and 10,000 deaths. "We think these deaths are preventable, and they could have been prevented had those moratoriums been kept in place," says Leifheit. We also speak with tenant rights activist Tara Raghuveer, who says the federal evictions moratorium "wasn't good enough to begin with," but allowing it to expire would leave "millions of families vulnerable to eviction within the first 20 days of the next year." #DemocracyNow Democracy Now! is an independent global news hour that airs on nearly 1,400 TV and radio stations Monday through Friday. Watch our livestream 8-9AM ET: https://democracynow.org Please consider supporting independent media by making a donation to Democracy Now! today: https://democracynow.org/donate

Miami residents priced out of a city built for the rich

 Here is the link. 

Miami is one of the worst cities in the U.S. to live in when it comes to affordable housing, and residents pay among the highest share of their incomes on rent. But a recent plan endorsed by the city would pave the way for creating 12,000 affordable housing units by 2024. Special correspondent Alicia Menendez reports as part of our series, “Chasing the Dream: Poverty and Opportunity in America."


San Francisco turned ghost town? Here's how empty the city really is

 Here is the link. 


Dishwasher: Back to work

 Dec. 28, 2020

Introduction

It is hard for me to figure out how to make it work. I did study how to replace the latches, but the handyman just pushed hard and it is back to work. 

Dish washer 

It is hard for me to handle roaches. I spent hours to work with people and figure out how to get rid of those roaches. Now it is under control. I do not know how I solve the problem with current renter. 


Landlords warn NYC is on the 'brink of catastrophe'

 Here is the link. 

Landlords are often seen as the bad guys, the people you have to pay on time every month. But just like tenants, many of them say they've been struggling to make ends meet during the coronavirus pandemic -- and they believe the city is on the brink of catastrophe. While we've heard from people who have moved from New York City to places across the country, at least temporarily, during the pandemic, 7 On Your Side Investigates spoke with some of the small landlords left behind.

Kitchen pipe: So many issues - How did I survive so many repairs?

 Dec. 28, 2020

Introduction

It is hard for me to survive as a home owner. I only have one home, and I lived there from 1999 to 2010. I have to learn how to survive to go through pandemic as well. 

Kitchen pipe 

I got complaint after the renter moved in less than two weeks. The pipe was broken, and I spent two hours to contact contractors. At least I have to pay over $200 dollars for pipe for the work. 

I always stay calm since I know that housing is most important for people. 

From 1999 to 2020, 21 year old at least pipe - got rotten 





After the repair, 



Why many companies are relocating to South Florida amid Covid-19

 STWD stock 

Here is the link. 


INTC stock: Plan to purchase 100 shares

 Here is the link. 

  • Trading at 46.8% below our estimate of its fair value
  • Earnings have grown 18.7% per year over the past 5 years
  • Pay a reliable dividend of 2.8%
Risk analysis
  1. Earnings are forecast to decline by an average of 3.8% per year for the next 3 years
  2. Has a high level of debt


EXPR stock: Comparison between 5/4/2018 and 12/28/2020

 Here is the link. 

I like to understand what is difference between 2018 and 2020

2018 6.67 USD - Sept 1, 2017

5/4/2018            2,163 (Revenue) Net income 22.06  Expense 801

10/30/2020        1,384 (Revenue) Net income -493.79  Expense 811

2020 Dec 28, 2020 1.02 / share, Dec. 28, 2020


DateRevenueNet Income*G+A ExpensesR&D Expenses
10/30/20201,384.76-493.79811.48-
7/31/20201,551.19-406.54830.91-
5/1/20201,778.2-308.47873.83-
1/31/20202,019.19-164.36910.03
11/1/20192,040.9-23.83570.72-
8/2/20192,067.37-12.76574.71-
5/3/20192,088.26-0.82576.65-
2/1/20192,116.349.63581.91-
11/2/20182,187.638.12812.66-
8/3/20182,176.0636.18804.86-
5/4/20182,163.6622.06801.37

FEYE stock: 58% share price increase - tips

Dec. 28, 2020

Introduction

I spent over two hours to work on equity research, I like to write down what I learn and focus on reading and learning. 

Facts 

  1. FireEye didn't make a profit in the last twelve month;
  2. Expect strong revenue growth - postpone profitability to grow revenue fast - uninspiring
  3. Last three year FireEye grew at 6% annually
  4. Dec 2019 Revenue 889 m/ yr, earning -257 m/ yr

CHS stock: Simple wallstreet

 Here is the link. 

Price to Book ratio

PB vs industry: CHS is good value based on its PB Ratio (0.7x) compared to the US Speciality Retail industry average (2.2x).

PB ratio 

company 0.7x, industry 2.2x, Market 2.1x

Earnings and revenue growth forecasts

Oct. 30, 2020

1.465 b/ yr

Earning -US$285m/ yr

22% -> 30% gains 

I shared CHS went up 22% this morning to wechat investment group, and total gain today is 30%. I am not sure why it went up. 




CHS stock: Yahoo -> Finance -> Conversation

 CHS - 20% gains - 2,831,000 shares

I like to learn from comment. I like to see my thinking process, and make adjustment. 

It is immaterial how many shares I am short. I never worked for Chicos. I see a highly mismanaged company conceal the real problems with their company. I see them profitting from their mistakes and fooling investors. Then I see foolish investors tout the disastrous numbers of a company that is likely going bankrupt. The longs who post are doing an injustice to those should know the truth of a company accumulating debt over $1 Billion. It is a near conspiracy to cover it up. Larry is right, very few people every read numbers of the 10Q and more invest off the comments of the conference call. This would be bad for most investor portfolios.


INTC stock: Yahoo -> Finance -> Conversation

Comment:

Intel is facing a lot of headwinds. The great news for Intel is that Microsoft and Apple make up less than 5% of Intel’s $80 billion per year revenue which has grown the last few years. Does it hurt, sure it hurts. But from a profitability stand point, the deal that Apple and Microsoft have with Intel will be quickly replaced with higher margin customers. Demand in this space is tremendous now and over the next 10 years.
Over the last 2-3 years Intel had increased its fab capacity by 100% and they are running at full capacity and then some.
Intel’s investment in Cloud, AI, and autonomous driving will keep Intel growing revenue and profits.
Intel’s 2020 revenue is expected to be close to $80 Billion with a “B”!!!! Net profit of almost $18-$19 Billion!
To put that in perspective, If you add up AMD’s, Nvidia’s, and Amazon’s net Profit for the year, you get close to Intel’s! Think about that for a moment.
Facts are, you can’t deposit market sentiment in the bank, you can only deposit $$!
In the next 3-5 years, I think investors that bought at these levels will be very happy with their investment. Intel will prove to be a gem in this space that the investors that pay attention to fundamentals will be greatly rewarded




Explained | The Stock Market | FULL EPISODE | Netflix

 Here is the link. 

In partnership with Vox Media Studios and Vox, this enlightening explainer series will take viewers deep inside a wide range of culturally relevant topics, questions, and ideas. Each episode will explore current events and social trends pulled from the zeitgeist, touching topics across politics, science, history and pop culture -- featuring interviews with some of the most authoritative experts in their respective fields. In this episode: Does the stock market accurately reflect the status of the economy? Finance specialists discuss market history, valuations and CEO incentives. US Rating: TV-MA. This show is designed for for mature audiences only.



Sunday, December 27, 2020

DealBook 2016: The Long and Short of Activist Investing

 Here is the link. 

Bill Ackman, C.E.O., Pershing Square Capital Management LP



For sale: The American dream | Fault Lines

 Here is the link. 

The US' housing bubble burst nearly six years ago, but the worst may be yet to come. After a landmark settlement, the major banks have lifted a freeze on foreclosures and government relief has been too small to make a difference. "We are often portrayed as the bad people, like we basically just come in and make all the money from people who are in bad situations. But the fact is, if we don't buy the property then the bank [will] take the property back."

Minimum wage: A life full of difficult choices

 Here is the link. 

One dollar for a meal - usually homeless people, now it is for minimum pay job people. 

Seven days a week / Need a day off - 17 years in a row - basically how much you need

Support family in Cuba - 

Poverty in Canada - 

What am I doing wrong? Feeling normal 

What quality of life can minimum wage workers afford?

 Here is the link. 

$9/ hour on Mcdonalds - 

Have roommates - $550/ month, two of them shares - food stamp 

30 miles away - Shop lifting - high school - stealing clothes - homeless situation - 

Rather work instead of on state assistant

$27/ hour - without public or private help 

Outskirts of ...

$9/ hour - $290/ month housing, $300/ month for food stamp 

No sick pay - 

Hard for them to meet basic needs - they go out working - basic needs - infants/ afford housing, food and other things.

Tax payer - basic needs - 

Complete out of ...

Situation - I am anger - instead of