Tuesday, July 14, 2020

Leetcode discuss: 865. Smallest Subtree with all the Deepest Nodes

Here is the link. 

C# mock interview practice with optimal time complexity

July 14, 2020
865. Smallest Subtree with all the Deepest Nodes

Introduction

It is the second algorithm in my mock interview today. It took me less than 30 minutes to come out the idea and write the solution. Also the solution is designed with optimal time complexity O(N), N is total nof nodes in the tree, and space complexity is O(1).

Case study

I asked myself to work on a simple solution, and make it work first.
The test case is a binary tree like root 1, left 2, right 3, and right.right = 4.

I like to apply post order traversal, so that each recursive function will return three things, first is longest path from root to leaf node, second one is the TreeNode which is candidate for the deepest node, third one is to track it's longest path to leaf node.

Time complexity
O(N), N is total number of nodes in the tree.

/**
 * Definition for a binary tree node.
 * 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;
 *     }
 * }
 */

public class Solution {
    public TreeNode SubtreeWithAllDeepest(TreeNode root) {
        // the idea is to apply post order traversal
        // if there are two children, both have same depth - return root
        // if one is bigger, than go to the bigger
        // recursive function is design to return depth from root to leaf node maximum path        
        var result = runPostOrderTraversal(root);
        return result.Item2; 
    }
    
    ///  root 1, left 2, right 3, and right.right = 4
    private Tuple<int, TreeNode, int> runPostOrderTraversal(TreeNode root)
    {
        if(root == null)
        {
            return new Tuple<int, TreeNode, int>(0, null, 0); 
        }
        
        // Left, right
        var left = runPostOrderTraversal(root.left); // 2
        var right = runPostOrderTraversal(root.right);  
        
        var path1 = left.Item1;
        var path2 = right.Item1; 
        
        if(path1 == path2)
        {
            return new Tuple<int, TreeNode, int>(path1 + 1, root, path1 + 1);    
        }
        else if(path1 < path2)
        {
            return new Tuple<int, TreeNode, int>(path2 + 1, right.Item2, right.Item3);  
        }
        else
            return new Tuple<int, TreeNode, int>(path1 + 1, left.Item2, left.Item3); 
    }       
}


XOM stock: June 2020


CVX stock: June 2020

July 14, 2020

CVX stock 


DOW oil stock: XOM and CVX

July 14, 2020

Introduction

I got up around 6:15 and worked two hours. I did learn something today, and two biggest oil companies in DOW went up 2%, so my Canada portfolio also went up. 

Case study

6:45 AM HSE.TO $4.15, I thought about purchase back 2000 shares sold on the price $4.26. I hestitated 20 minutes, it went back to $4.26. So I asked why, and then I searched Dow two oil companies's stock went up. 

All other Canadian oil stock went up as well.







HSE.TO stock: My update on positions

July 14, 2020

Husky Energy

Husky Energy (TSX:HSE), one of the country’s biggest energy companies, has had an unpleasant year so far. The stock has plunged more than 55% year to date and trades at $4.5 apiece at the moment.
Crude oil has had a rough ride in April, as demand plunged on the back of shutdowns while producers kept filling up the storage tanks. Husky Energy trimmed its dividends by 90% and reported losses of more than $600 million in the last quarter.
But importantly, the integrated energy company looks well placed on the liquidity front and will likely weather the crisis. As oil prices have recovered subsequently, TSX energy stock Husky has almost doubled in the last three months.
Many market participants and top banks turned bullish on crude oil, as major economies re-open and could see an increase in demand. This might also boost energy company stocks like Husky Energy in the short to medium term.
Investors should note that these TSX stocks offer higher growth potential but also pose a higher risk. Investors who can bear excessive volatility may consider these names.
The post 3 TSX Stocks Under $5 That Could Double Your Money appeared first on The Motley Fool Canada.


Monday, July 13, 2020

TSLA stock: analysis of TSLA stock

巨大财富效应下,马斯克的个人财富当天就增长61亿美元(约427亿元),同时以705亿美元身价超越股神巴菲特,成为全球第七大富豪。
 
值得注意的是,美国现在贫富两拨人呈现一种极端分化,一边是贝佐斯、马斯克代表的超级富豪身价暴涨,一边是失业人数破4000万,创下1930年大萧条以来新高。

为啥?因为这轮史无前例的全球放水,正让楼市、股市、黄金等资产价格上涨,富人直接受益越来越富,而普通人手里的货币却面临贬值....
 
那么,马斯克们是如何从大放水中获利的,这样下去又将导致什么后果?

一个月内,美联储向市场投放数万亿美元,而且祭出08年金融海啸都没用过的大招救市:无限供应美元,要多少印多少。相当于孤注一掷,打光所有弹药,剩下的听天由命了。
 
美联储带头后,各国央行紧随其后,轰轰烈烈的放水开始了。据路透社消息,到5月11日,全球各国累计放水已高达15万亿美元,相当于去年全球GDP的17%。

本来全球央行放水,是要拯救实体经济的,尤其是被疫情暴击的中小企业、消费者,大家该贷款贷款,该消费消费,一起共克时艰,保卫经济。
 
但市场毕竟是逐利的,各国相继公布的惨淡经济数据证明,水漫金山的钱并没有流入实体经济。
 
最直观表现就是,美联储3月带头疯狂印钞,但二季度美国失业人数屡创新高,高盛等知名机构也一致预测美国二季度GDP将暴跌40%,超越08年金融危机时的跌幅。
 
没去实体经济,那钱去哪了?答案是流向各种资产。

3月全球股市暴跌,仅美股就蒸发了100万亿,大放水后,全部暴力反弹,纳斯达克指数目前已经新高,就是10年困守原地的中国股市,上周也开始暴动。

同时,黄金价格大涨,创下9年来新高....实体经济和金融资产之间,大家明显用脚投票了。

所以,全球央行印的10几万亿美元里,有相当一部分流入了楼市、股市、黄金等资产,而持有这些资产的人也就更有钱。
 
反映到现实中,就是美股大涨,苹果领衔的微软、亚马逊等科技巨头个个疯涨创新高,持有大量股票的巨头创始人们越来越富。

这里面有两个人极具代表性,一个是世界首富贝佐斯,另一个就是马斯克。7月3日,因为亚马逊市值连续大涨,贝佐斯身价突破1700亿美元,刷新了自己的记录。

而马斯克,因为全球量化宽松,不仅彻底扭转特斯拉困境,自己顺便还超越了巴菲特。

这是实打实的放水受益方,如果不是百年难遇的疫情,他还眼巴巴等着上海工厂解决产能危机呢。

那么,实体经济与金融资产严重背离,将导致什么?
 
首先是巨大泡沫。以特斯拉为例,它是美股最骚之一,一会新能源,一会苹果第二,一会殖民火星,故事实在太丰富了,放水后大量热钱杀到股市,轻轻松松就被吸引了。
 
所以其股价和坐上猎鹰火箭一样,一路被推高,一天就能涨出一个福特。足够疯狂,但不合理。

Stock analysis: Second quarter

本周,摩根大通、美国银行、高盛和富国银行等华尔街主要金融机构将率先公布财报,随后百事可乐、强生公司、雅培公司和奈飞也将陆续公布业绩。


根据金融数据机构Refinitiv的数据,目前市场对标普500指数企业第二季度综合盈利预期下降43.4%,这是自2008年金融危机以来最糟糕的季度业绩。


由于新冠疫情带来巨大不确定性,许多公司此前没有给出盈利指引。Refinitiv预计,金融业盈利下降52%以上,而科技公司盈利预计只会下降8%。最糟糕的行业将是能源行业,预计盈利暴跌154%,其次是非必需消费品,预计下降114%。


Ally Invest首席投资策略师Lindsey Bell表示,美股将迎来金融危机以来最糟糕的季度。二季度末以来的趋势、新冠病例的增长以及管理层的前景展望等都将受到投资者高度关注,并可能对市场产生巨大影响。


尽管市场一致预期二季度美国经济将面临大萧条以来最严重的萎缩,美股却在二季度创下数十年来最佳季度表现。自3月23日触及底部以来,纳指已大幅反弹超过50%并创下历史新高,而标普500指数和道指也反弹超过35%。


DoubleLine Capital首席执行官、“新债王”杰弗里冈拉克(Jeffrey Gundlach)认为,美股在二季度的创纪录反弹表现实际上是由所谓的“Super 6”六大科技巨头驱动的,“Super 6”包括脸书、亚马逊、苹果、Alphabet、奈飞和微软。


冈拉克说:“要是没有‘Super 6’,美国股市就没有盈利增长。美股过去五年没有盈利增长。如果将它们剔除,那就什么也没有了。”


以苹果公司为例,自3月低点以来,苹果公司股价累计涨超71%,远超同一时段标普500指数近40%的涨幅。


标普500指数的五大成分股——苹果公司、微软、亚马逊、Alphabet和脸书,2020年以来股价均获两位数百分比增长,而它们在该指数中综合权重接近23%,对指数拉升做了重要贡献。


近期,许多其他科技类公司也大幅上涨。疫情利好的公司如奈飞和Zoom,股价二季度以来屡创新高,截至上周五美股收盘,Zoom市值已达780亿美元。

警惕美股风险


冈拉克认为,目前的一切都是由价格驱动的,而不是盈利驱动。小盘股不仅没有盈利增长,反而遭受了巨大的打击。


冈拉克预计美股市场的盈利水平与2016年相当,彼时市场水平较目前低三分之一。他补充说:“因此,基本面与操纵市场的方式完全不同步。”


与此同时,冈拉克推测一些救济金正在流入股市,异常活跃的期权市场助长了此轮狂热。“股市的上涨部分是由于政府给失业者的钱。我认为这很危险。”


摩根大通分析师诺曼德(John Normand)在报告中指出,虽然美股市场并没有被严重高估,但下行风险不容忽视。

Technology stock: overbought and prices are inflated

此前数日上涨的科技股在周一交易日一度上涨后下跌,脸书、亚马逊、网飞、微软、Alphabet等均出现下跌。


道琼斯指数和标普500指数连续两周上涨,科技股的反弹推动纳斯达克指数在连续三周上涨后创下新高。7月,道琼斯指数和标普500指数分别上涨了1.0%和2.7%。科技股为主的纳斯达克表现更好,本月上涨10.7%,亚马逊、苹果、网飞、Alphabet都创出新高。


有华尔街分析警告称,目前各股上涨的区间仍然有限,部分高股价的科技股正在被超买,因此对于前景持谨慎态度。

TSLA stock: went up 16% and then down 3% in the end of July 13, 2020

Here is the article. 

多年以来,特斯拉的估值以及该公司创始人马斯克一直遭受华尔街的争议。包括“熊市陷阱报告”(Bear Traps Report)编辑Larry McDonald在内的一些人认为,最近特斯拉涨势不是受到基本面驱动,而是因为投资者预计该公司有可能被纳入标普500指数而抬高了股价。

McDonald指出,现在“抢跑”买入特斯拉的逻辑是逼迫指数给公司更高的权重,后续那些ETF和基金将以更高的价格买更多的股票,届时投机资金可以大举离场,将包袱甩给指数。

摩根士丹利汽车分析师Adam Jonas日前亦表示,“特斯拉几乎不受挑战的统治地位的日子已经屈指可数了。”他对该股的评级为减持,目标价为740美元,较上周五收盘价低52%。

但包括JMP Securities在内机构仍看多特斯拉股票,分析师Joe Osha在最近给客户的一份报告中表示,到2025年,特斯拉的年营收将达到1000亿美元。在最新的完整财年中,特斯拉创造了246亿美元的营收。

Leetcode discuss: Better writer showcase

July 13, 2020

Introduction

It is so interesting to see one upvote each for two discuss post I wrote last few days. It is better for me to record this achievement and push myself work hard.

Leetcode discuss

I push myself to write one post each time for my practice. So I do see my performance is better as  a writer.



403 Frog jump, here is the link.
1080 Insufficient Nodes in Root to Leaf Paths, here is the link. 

TSLA stock: Tesla jumps 14% on S&P 500 inclusion speculation — Now the 10th biggest U.S. stock by market value

Here is the article.

Shares of Tesla hit a new all-time high on Monday, extending the stock’s record run, as investors continue to pile into the Elon Musk-led company. And as the company’s valuation climbs ever higher, speculation is growing that the company will soon join the S&P 500.

After Monday’s open, Tesla’s market value increased to $321 billion, according to FactSet. That makes it the 10th largest U.S. stock by market value, leapfrogging Procter & Gamble, according to FactSet.



Apple Stock Is Up 30% This Year. What's Next?

Here is the article. 

30% up in 2020
190% up from January 2019

While work-from-home stocks like Zoom Video and Peloton Interactive may have been getting much of the attention in financial media as the highfliers of the current market rebound, the world's most valuable publicly traded company has been regularly hitting new all-time highs as well. Apple (NASDAQ:AAPL) now has a market capitalization of $1.65 trillion, with shares trading above $380. To get here, the stock had to rise about 90% over the past 12 months and 30% in 2020 alone.

With the tech stock climbing so much, many shareholders may be on edge, wondering if they should book their profits. On the flip side, the stock's strong price action may have attracted some new investors who are wondering whether there's still upside ahead for the tech giant.

Amazon stock: Bubble burst?

Here is the link.

Amazon (NASDAQ:AMZN) is another stock that's at all-time highs, recently breaking through the $3,000 mark. The tech giant is another stay-at-home stock that's been a popular buy among investors during the coronavirus pandemic.
The rally that Amazon's been on is incredible, given that on April 30, when it released its first-quarter results, the company failed to beat analyst earnings expectations. But revenue was still strong, with the quarterly top line up 26.4% year over year, reaching $75.5 billion. The company expects revenue for the second quarter to fall between $75 billion and $81 billion, representing year-over-year growth anywhere between 18% and 28%. 
The stock initially tumbled after the Q1 results and would fall below $2,300 on May 1. But it's been red-hot since then, and its year-to-date returns are now north of 70%.
The challenge for Amazon is that there's a risk from the demand side that a recession could lead to less spending in upcoming quarters. As businesses are operating at reduced capacity, there's a potential for supply issues to also affect the online retailer's results. A disappointing second quarter could send the overpriced stock into a tailspin. 
Shares of Amazon are currently trading at more than 130 times earnings and 22 times book value. Its price-to-sales ratio of about 5 compares favorably against Teladoc, but all the multiples combined paint a picture of an extremely overpriced stock, one that could be vulnerable to a correction.
When the markets crashed in March, shares of Amazon were trading for close to $1,600 -- almost half the price they've reached today.

Actionable Items


Amazon at price over $3000
22 times book value
130 times earnings

$1600 half of price - Market crash - March 2020

Q1 result - May 1, 2300 , year-to-date up 70%


Growth stock: FB stock and others

Here is the article.

Unlike value stocks, growth stocks tend to be more expensive than the average stock in terms of metrics like price-to-earnings, price-to-sales, and price-to-free-cash-flow ratios. Yet despite their premium price tags, the best growth stocks can still deliver fortune-creating returns to investors as they fulfill their awesome growth potential.

To provide you with some examples, here are 10 excellent growth stocks available in the stock market today:
Company3-Year Sales Growth CAGRIndustry
Shopify (NYSE:SHOP)59%E-commerce
Alibaba (NYSE:BABA)55%E-commerce and cloud computing
Square (NYSE:SQ)40%Digital payments
MercadoLibre (NASDAQ:MELI)40%E-commerce
Facebook (NASDAQ:FB)37%Digital advertising
JD.com (NASDAQ:JD)37%E-commerce
Netflix (NASDAQ:NFLX)32%Streaming entertainment
Amazon (NASDAQ:AMZN)27%E-commerce & cloud computing
Salesforce.com (NYSE:CRM)27%Cloud software
Alphabet (NASDAQ:GOOG), (NASDAQ:GOOGL)21%Digital advertising
CAGR = compound annual growth rate. Data sources: Morningstar, Yahoo! Finance