Sunday, November 8, 2020

System design: System Design Analysis of Google Drive

 Here is the article on medium.com written by Samsung architect. 

Here are highlights about my favorite content:

I will add highlights later. I need to spend more time to learn this topic. 

What will happen when the client is offline?

A client component, Watcher, will observe client-side folders. If any change occurs by the user, it will notify the Index Controller(another client component) about the action of the user. It will also monitor if any change is happening on other clients(devices), which are broadcasted by the Notification server.

When the Metadata service receives an update/upload request, it needs to check with the metadata DB for consistency and then proceed with the update. After that, a notification will be sent to all subscribed devices to report the file update.

Find algorithms to work on: Twitter + programmercoach

 I like to spend at least one hour to go over last 100 weekly contest, and then find some of them to work on. 

If I continuously work on past contests in the weekend, then I can quickly figure out my weakness. Also I need to improve my performance. 

I like to learn a few things from this link. 


Kadane’s Algorithm: Dynamic programming

 Here is the article. 


Saturday, November 7, 2020

Celebration: Google phone screen - another achievement

 Nov. 7, 2020

Introduction

It is my hobby to write blogs and practice algorithms. It is my frugal life style and put my health and fitness in top priority. I did run this Saturday morning starting 8:30 AM in Burnaby central park, and I did have selfies to celebrate, and make this weekend more memorable. 

Google phone screen

It is so unbelievable achievement to pass Google phone screen first time in my life. As a career woman, I recorded a video in central park Burnaby using one app, but it got lost. I plan to go back tomorrow morning to make another one. 




陈建敏,vancouver, BC 16:10

我跑步自拍。庆祝一下谷歌让我进入onsite

陈建敏,vancouver, BC 16:11

我的帽子是谷歌去年西雅图聚会送给我的。

I missed important rebound in stock last two days. So I learn the lesson to stay in the moment. 

There is always risk to take. Always stay positive. 

Here is my youtube video. Here is another video. 


Thursday, November 5, 2020

Leetcode discuss: 1248. Count Number of Nice Subarrays

 Here is the link. 

Second practice - C# - slide window - less than K

Nov. 4, 2020
Introduction
I like to spend 10 minutes to talk about importance to learn to write a simple and elegant solution from lee215. The algorithm can be solved using slide window, and it should take less than 10 minutes.

Slide window
I like to copy the idea using slide window to solve the problem. Here is lee215's solution. I will write down more analysis to make it more clear.

First it is to convert k odd number to another problem using less than k.
Second is to calculate the array with less than k odd number, how many subarrays? For example, [1, 2, 3, 4], k = 2.

public class Solution {
    public int NumberOfSubarrays(int[] A, int k) {
        return atMost(A, k) - atMost(A, k - 1);
    }

    public int atMost(int[] A, int k) {
        var result = 0;
        var left = 0;
        var n = A.Length;
        
        for (int right = 0; right < n; right++) 
        {
            k -= A[right] % 2;
            
            while (k < 0)
            {
                k += A[left] % 2;
                left++;
            }
            
            result += right - left + 1;
        }
        
        return result;
    }
}


Wednesday, November 4, 2020

Progress report: Oct. 4 - Nov. 4, 2020 - 10 things I do better this time

 Nov. 4, 2020

Introduction

I just could not believe that I learn much more because I have to work on small tasks like writing C# for  algorithms. I have to write down 10 things I do better this time to prepare for Google phone screen!

10 things I do better this time

  1. I took Amazon online assessment but I failed the test; I could not speed up my coding and had trouble to play with Hackerrank web compiler using C#. I did it before Google phone screen, one week ahead. 
  2. I started to try to record videos for algorithm practice
  3. I went through a lot of dynamic programming algorithms, I learn how to read other people's sharing
  4. Hard level algorithm is so interesting, and I just could not believe that I waste so many resources. So many people share the solution and it is so easy for me to learn hard level algorithms.  
  5. I started to play leetcode weekly contest after I failed Amazon online code assessment second time in 2020. 
  6. It is most important to expedite my coding. Time is limited. I should practice more. 
  7. I practiced a few times on pramp.com system design and behavior interview. I learned a lot on system design. I started to read Microsoft Microservice book. 
  8. ...

Key largo portfolio: Portfolio update on Nov. 4, 2020


I have less than one hundred dollar gains from last 18 months, but I had chance to purchase so many stocks and learned so many business about United States, coronavirus impact on our economy. 

God blesses United States and Canada. I like this investment so much, keep learning and I just need to be patient, do not gamble too much. Stay small size, learn good money management habit. 


Leetcode discuss: 940. Distinct Subsequences II

 Here is the link. 

Nov. 4, 2020
940. Distinct Subsequences II

Here are steps I took in order for me to learn a hard DP problem.

  1. Read GeeksforGeeks;
  2. Copy C# code, ran into failed test caes;
  3. Learn another C# submission;
  4. Work on a test case

Given a string S, count the number of distinct, non-empty subsequences of S.
Input: "abc"
Output: 7
Explanation: The 7 distinct subsequences are "a", "b", "c", "ab", "ac", "bc", and "abc".

Define C#: var dp = new int[4]; // s = "abc"
dp[3] = length <=3 distinct subsequences
dp[2] = lenght <=2 distinct subsequences

To remove duplicate, use visited two dimension array.
var visited = new int[length + 1][26]
Go over step by step "abc", how to get the result of 7?
Index = 0;
'a' visited[0,0] -> set true
dp [1, 1, 0, 0] 'a'

"a" - distinct subsequence should be one. "a"

Index = 2
start = 0 'b'
visited[0, 1] -> set true
dp [1, 1, 1, 0]
start = 1
visited[1, 1] -> set true
dp [1, 1, 2, 0]

"ab" - distinct subsequence should be three. "a","b","ab"
Thinking, ask to myself?
Q1: dp[2] = 2, explain to myself, what is meaning of 2.
A1: Append 'b' to all subsequence's in the end, "" + "b" = "b", and "a" + "b"= "ab", two more subsequences are added. Make sense?
Q2: What are total subsequence's number?
A2: dp[1] + dp[2] = 3.

Index = 3
start = 0 'c'
visited [0, 2] -> set true
dp [1, 1, 2, 1] <- start = 0
visited[1, 2] -> set true
[1, 1, 2, 2]-> start = 1
visited[2, 2] -> set true
[1, 1, 2, 4] -> start = 2

The idea is simple. First go over all subsequence with 'c', add them together, each one will append 'c' at the end. In the same time, update dp[index] to include 'c' as well. Two tasks should be completed.

"abc" - distinct subsequence should be 7. "a","b","ab", four are added in the last step - index = 3, itself, "c", add "c" after one of each string {"a","b","ab"}.

The total of "abc" distinct subsequence should be 7.

Advice
As a hard working programmer, it is important for me to go over the test case "abc", each step I like to make sure that code will work for those intermediate result.

The order of any subsequence has to be maintained as the original string. The only challenge is to remove duplicated ones.

Time to work on
It took me more than a few hours to study and write down some notes.Patience is the important. Work on a small test case and try to argue to myself what is true here.

It is hard to be an expert on dynamic programming algorithm. Right now, I just like to learn one hard level algorithm. It took me two days, over 8 hours.

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

namespace _940_distinct_subsequence_II
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = DistinctSubseqII("abc");
        }

        /// study code
        /// https://www.geeksforgeeks.org/count-distinct-subsequences/
        /// I could not make it work, so I studied another one
        /// https://leetcode.com/problems/distinct-subsequences-ii/discuss/560060/Simple-C-DP-Solution
        public static int DistinctSubseqII(string s)
        {
            long MOD    = 1000 * 1000 * 1000 + 7; 
            long result = 0;
            var  length = s.Length;

            var dp      = new long[length + 1];
            var visited = new bool[length + 1, 26];

            dp[0] = 1;

            for (int index = 1; index <= s.Length; index++)
            {
                var endIndex = s[index - 1] - 'a';
                    
                for (int start = 0; start < index; start++)
                {
                    if (!visited[start, endIndex])
                    {
                        visited[start, endIndex] = true;

                        dp[index] += dp[start];
                        result  += dp[start];

                        dp[index] %= MOD;
                        result  %= MOD;
                    }
                }
            }
               
            return (int)result;
        }
    }
}

Actionable Items

Make a youtube video to explain the algorithm. 


How to Use the Dividend Capture Strategy

 Here is the article. 

Dividend Timeline

At the heart of the dividend capture strategy are four key dates:

  • Declaration date: The board of directors announces dividend payment. This is the date when the company declares its dividend. It occurs well in advance of the payment.
  • Ex-dividend date (or ex-date): The security starts to trade without the dividend. This is the cut-off day for being eligible to receive the dividend payment. It's also the day when the stock price often drops in accord with the declared dividend amount. Traders must purchase the stock prior to this critical day.
  • Date of record: Current shareholders on record will receive a dividend This is the day when a company records which shareholders as eligible to receive the dividend.
  • Pay date: This is the day when the dividend is paid and the company issues dividend payments

Sunday, November 1, 2020

Work with peer: Mock interview with a friend

 Thank you for the mock interview using coin change. 


 I wrote two discussion posts. My solution written in mock interview was wrong, I debugged the code and it could not find minimum coins. 

Here is the discussion post. 


I wrote the correct one using BFS, too hard to write, better using dynamic programming. Here is the link. 


Word break algorithm you worked on:
BFS solution Java - I interviewed senior programmer this afternoon working at SAP. Here is the link. 


I wrote C# solution to copy his idea. Here is the link. 

labuladong 的算法小抄

 Here is the link. 

I plan to work on this link and learn a few hours today. It is such a good link for preparing for Google phone screen in a week. 


Leetcode article: Requesting guidance from those who solved 1000+ Leets so far!

 

I spent over 20 minutes to write some ideas to answer the question. 

Read More

I have solved over 1170+ Leetcode problems (including database and shell scripting problems). However, when I try to particular in a weekly coding contest, I can hardly finish all 4 problems (usually only 2 or 3 problems finished) within the 1.5 hrs time window. It seems to me that solving a lot of Leetcode problems in a relatively relaxed setting does not help me very much in competitive programming (under time constrain). And suggestion / advice on how to become more efficient and more competitive in programming contests? Any such suggestion & advice will be much appreciated!

1
Hide 1 reply
Reply
Share
Report
jianminchen's avatar
Read More

I have same concern. I only solved 520 algorithms.
I am trying a few ideas recently. Three things I can think about.

  1. Read Leetcode discuss post from lee215 more often.
  2. Read more blogs from GrandYang on Leetcode.com.
  3. Continue to practice same question, like word break, lowest common ancestor
  4. Go over same type of questions together.
  5. Keep practice. Solve Leetcode using Python language or JavaScript again.

More on item 1, today I copied his code and translated to C#, it took me 10 minutes, but I wrote 40 minutes in weekly contest using my own idea. Lee315 is a great thinker, crafting skill is top level.

More on item 3, I practiced Lowest common ancestor three months, ask the same algorithm three months as an interviewer, but I still fail tree algorithm on weekly contest. I think that problem solving skills cannot be improved on one area like tree algorithm first. We have to work on all of them together.

More on item 4, I reviewed 50 dynamic programming algorithm last week using the link: Leetcode userful links - https://leetcode.com/discuss/general-discussion/665604/important-and-useful-links-from-all-over-the-leetcode/742440

More on item 5. I practice interviews on interviewing dot io last two years over 300+ times. I got a lot of advice how to improve, and I was able to advance my ranking to top 40%, and got invited to interview with startup on interviewing dot io because of my performance as an interviewee last month. But I still could not improve my weekly contest performance. Most of important is to write a lot of code every day, try to write same code shared on Leetcode discuss post, compare difference, and learn more crafting ideas, get smart on debugging and trouble shooting, get used to read code and find bugs quickly. No need to use debugger.

Take some time off to read some books. I like to recommend a book called "The art of readable code". I wish that I read similar book 20 years ago.

Saturday, October 31, 2020

SU.TO stock: WARNING: Suncor Energy (TSX:SU) Stock Could Reach $10

 Here is the article. 

I just bought 700 shares of Suncor stock. My average cost is $15.00 dollars. I should not gamble too much. I am planning to hold for long term since I analyze Suncor is at the bottom. But it is not, another 30% to drop before 4th quarter financial result. 


The year 2020 is proving to be terrible for Suncor Energy investors, as its stock has tanked by about 65% so far. The stock has underperformed the broader market as well as most of its peers.

The S&P/TSX Composite Index is currently trading with about 8.2% year-to-date losses. The shares of other energy firms such as Whitecap Resources and Seven Generations Energy have slipped by 56% and 47%, respectively. During the same period, its other peer Tourmaline Oil has risen by 13%.

In Q3, Suncor Energy posted an adjusted net loss of $0.20 per share against a profit of $0.72 per share in the same quarter last year. Bay Street analysts were expecting the company to report a less steep loss of around $0.12 per share.

Notably, it was the sixth consecutive quarter when the company’s earnings missed analysts’ expectations and the third quarter in a row when its earnings fell on a year-over-year (YoY) basis.

In the quarter ended September 2020, Suncor’s revenue was at $6.5 billion — about 35% worse than $9.9 billion in Q3 2019. The revenue also missed Bay Street’s expectation of $7.2 billion.

Similarly, the company’s adjusted gross profit of $2.33 billion was about 64.1% worse than the $6.49 in the same quarter of the last year.

While Suncor Energy’s management expects its operating performance to improve in the fourth quarter, most analysts don’t see that happening. Analysts estimate Suncor Energy to post a $212 million loss in the fourth quarter, which would lead to a massive $2.1 billion losses for the full year 2020.

The stock could fall below $10

As of October 29, Suncor Energy stock is trading at $15.09 per share. It’s currently hovering right above the major support level around $14.20 — formed back in 2002. A violation of this support level could trigger a massive sell-off in the stock and take prices further down towards the next support level of $9.60.

On the macro side, a prolonged pandemic along with predictions of a major economic slowdown are some of the factors that could keep energy demand low — at least in the coming few quarters. Low energy demand would certainly make Suncor Energy’s financial recovery plan more challenging. These are some of the reasons why I believe Suncor Energy stock could be headed towards $10.

It would be wise for investors to keep a close eye on the $14.20 support level and exit Suncor Energy stock position if it falls below this level. Instead, you can invest in any of undervalued TSX stocks right now.

Follow up 

Oct. 20, 2023

I did not invest on long term. I sold all SU.TO position, and then moved on other stocks. 


MIC stock: Private mortgage

 Back in June, I’d suggested that Canadians should buy Genworth MI Canada (TSX:MIC). The company is the largest private residential mortgage insurer in Canada. Shares of this TSX stock have climbed 26% week over week as of close on October 29.

Genworth is set to release its third-quarter 2020 results on November 2. In Q2 2020, the company saw total premiums written increase 17% from the prior year to $227 million. Canada housing has remained resilient in this historical crisis. Increased activity is good news for Genworth.

This TSX stock last possessed a price-to-earnings (P/E) ratio of 9.4 and a price-to-book (P/B) value of one. That puts Genworth in very attractive value territory. Moreover, it offers a quarterly dividend of $0.54 per share, which represents a 4.9% yield.

FTS stock: one of the top utilities in the country

 Fortis (TSX:FTS)(NYSE:FTS) is an elite option for Canadians on the hunt for TSX stocks that pay a dividend. This St. John’s-based company is one of the top utilities in the country. Fortis stock has climbed 2.8% in 2020 as of close on October 29.

The company is set to release its third-quarter 2020 results in early November. In Q2 2020, Fortis delivered adjusted net earnings of $0.56 per share compared to $0.54 in the prior year. Best of all, Fortis’s five-year capital plan of $18.8 billion remained unchanged in the face of the COVID-19 pandemic. This capital plan aims to significantly expand the company’s rate base and support annual dividend growth of 6% through 2024.

Shares of Fortis last had a favourable P/E ratio of 20 and a P/B value of 1.4. It last paid out a quarterly dividend of $0.4775 per share, representing a 3.7% yield.

CWB stock:

 Canadian Western Bank (TSX:CWB) is another TSX stock Canadians should consider adding right now. This regional bank has a large footprint in western Canada but is also making a push in the eastern part of the country. Shares of Canadian Western have dropped 20% so far this year.

In Q3 2020, the bank saw revenue increase 4% from the prior year to $226 million. Loans rose 5% to $29.7 billion, posting 10% growth in Ontario. Moreover, branch-raised deposits climbed 22% to $16 billion.

This TSX stock last had a very favourable P/E ratio of 8.4 and a P/B value of 0.7. Canadian Western offers a quarterly dividend of $0.29 per share. That represents a 4.7% yield. It has delivered dividend growth for over 25 consecutive years

CNQ.TO stock: I should look into and purchase some stocks

 Canadian Natural Resources (TSX:CNQ)(NYSE:CNQ) is the last TSX stock I want to focus on in this piece. This Calgary-based company is engaged in hydrocarbon exploration in western Canada and around the world. Its shares have dropped 47% in 2020.

Energy stocks have been throttled due to the pandemic, but demand is on track to recover in 2021. This TSX stock possesses an attractive P/B value of 0.7. Better yet, it last paid out a quarterly dividend of $0.425 per share. This represents a monster 8.1% yield. Canadians on the hunt for income and exposure to energy should consider Canadian Natural Resources right now.

The post 4 Amazing TSX Stocks to Buy With $2,000 appeared first on The Motley Fool Canada.

Su.TO stock: Market crash in November 2020

 

Troubles in the energy and gold sector

During the ongoing earnings season, most energy companies continue to report big losses due to weak demand. For example, Suncor Energy (TSX:SU)(NYSE:SU) announced its results earlier this week. It reported a massive $302 million adjusted net loss in the third quarter compared to a $1.1 billion profit in the same quarter of 2019. Lower energy demand amid the pandemic — along with narrowing cracking margins — took a big toll on Suncor Energy’s bottom line in the last quarter.

Low energy demand is also taking a big toll on energy firms’ revenues. In Q3, Suncor Energy’s revenue fell by 35% to $6.5 billion — much worse than $9.9 billion in the third quarter of 2019.

At the same time, the recent drop in gold prices is putting pressure on gold stocks. With no hopes of immediate economic recovery, energy stocks might continue to face troubles in the coming quarters. A sell-off in these two sectors could also lead to a market crash in the coming months.

Friday, October 30, 2020

Spooky housing stat: How troubled are consumers?

 Here is the link. 


Renters hard hit by pandemic

8 million behind on rent. 

6 million doubtful to pay now. 

Spooky housing stat - how troubled is the consumer?



221 Maximal square - plan to work on

 https://leetcode.com/problems/maximal-square/discuss/61803/C%2B%2B-space-optimized-DP

USA retirement benefit: My 14 years working experience from 1996 to 2010

 Oct. 30, 2020

Introduction

I like to look into my personal experience last 25 years in USA and Canada. I like to write something about building wealth and live happy life.  

1996 to 2010

I spent 14 years in United States. I still own a condo in Boca Raton, and I have to work on investment on my IRA and 401 K. 

2010 to 2020

I live in the city of Vancouver Canada over 10 years. 


Stock research: Read 10 loser everyday - learn more about business and challenges

 Fenviz -> screener -> top losers -> read top losers 10 of them every day. Ask questions. 

Another 200: 200 algorithm to practice

One idea is to learn how to program dynamic programming. I have strong interest to learn dynamic programming, but I need to learn together. 

Here is the good article to talk about patterns. 

Patterns


Minimum (Maximum) Path to Reach a Target
Distinct Ways
Merging Intervals
DP on Strings
Decision Making

Another 100: Leetcode dynamic programming algorithms

 Let me work on those dynamic programming algorithm first. 

Problem categories and related videos: (below)

Palindrome Based: LC 516, 5 647
Palindrome Partitioning: LC 132 133
Decode ways: LC 91
Stocks: LC 121 122 309 714
Path : LC 62 63 64
Jump Game : 55 45
Stairs: 70 746
Wildcard: LC 44 10
Word Break: 139 140
Max Sq & Rect: 85 221
Super Egg: LC 887
Coin Change: LC 322, 518, 441
Longest Common substring: 718

Others :

House Robber: LC 213, 198
Paint House : LC 256 265
Subarray : LC 53, 152
Subsequence LIS : LC 300 354
Math: LC 279 343 204