Monday, August 3, 2020

BitTiger: 顶尖架构师:如何设计一个Uber

Here is the link. 




BitTiger: 如何设计一个推荐系统

Here is the link. 




CVE stock: SimplyWall.st analysis

Here is the link. 


Husky energy stock: wallstreet.io analysis

Here is the page. I like to spend at least 20 minutes to review the content. 



System design: How to prepare and learn starting from CS fundamental

Path to SV Engineer

Step 1: CS Fundamental

computer architecture
operating system
Computer network
Software engineering

Step 2:
System design
Design by yourself

Step 3: 
Open source projects

Kafka
Spark
MongoDB
Redis

Step 4: Hands on

code by yourself



SimpleWall.st: Suncor energy stock

August 3, 2020

Introduction


As an investor, I have to watch myself to go through learning process to chase high price, and then sell when the price is low. I have to play with greedy and fear, also I like to build connections with other JTU alumni on my wechat group. I have to take it seriously. One thing is so good to learn from today - SimpleWall.St.

Suncor stock


I need to learn from my investment position: Suncor energy stock. And I do think that it is smart for me to learn from SimpleWall.st. 

Here is the link. 



SimpleWall.st: What if I am the product manager of SimpleWall.st?

August 3, 2020

Introduction

I came cross this website again through the article related to Intel stock research. I like to explore all the features of the website using a free account. I like to talk about product features on this website. It is challenging for me to be an intelligent investor, through the website, I do think that I can be much better one. 

My research

Compared to the owner of a small investor group on wechat, I do think that it is also a good investment to find a best website to pay for, and then I can evaluate how good the website will be. 

There are a few choices: Yahoo finance, Fenviz, MarketBeat, SimpleWall.st. 


BitTiger: 【面试中】系统设计怎么考?系统设计题怎么答?

Here is the link. 

System design common questions:

Uber
LinkedIn
Monitor System
Dashboard
Dropbox
Twitch
Google Doc
Google Sheet
Google File System
BigTable
MapReduce
Restful service
WhatsApp
WeChat
User System
SQL database
KV database
Netflix
Crawler
TineyURL
Task scheduler
RateLimitor
Flickr
Recommender System
Message broker
Elevator
Chess
ATM
Facebook
Twitter
Typeahead
Yelp

Template: SNAKE

  • Scenairo: case/interface
  • Necessary: constrain/hypothesis
  • Application: service/algorithm
  • Kilobit: data
  • Evolve





BigTiger: 系统设计的基本方法SNAKE原则

Here is the link. 

The process of defining the architecture, components, modules, interfaces, and data for a system to satisfy specified requirements. 



How to design NetFlix? 

Top level design:

Scenario:

Necessary: requirement/ assumptions

First step: ask how many users
  5,000,000 daily users
Second step: prediction
  2 - 10 times more - future, 3 months, Netflix - twice more users

125 users
3MBps -> peak bandwidth 3.75 Tb/s 

Storage 
  10KB
3 months later storage 5,000,000 * 2 * 10 = 100GB

Hard disk

14,000 movies
Total storage:

Application: 
service/ algorithms
Step 1: 
Step 2: 

Kilobit (Data)
First step:   

Evolve (How to advance system design?)
Step 1: analysis
  directions:
   Better: limitation
   Broad: scenarios
   Depth: small details

Angles:
  . Property
  

SNAKE:
Scenario
Necessary
Application
Kilobit
Evolve 

Micro: 
recommendations: 
u1 = {m3, m5, m7, m11)


Class Recommender{
}

Necessary (limitation)
prediction

Algorithm & Kilobit 

For movie liked by u1


   







Questrade.com: MY TFSA account




NYSE stock market:
August 3, 2020 11:05 AM

SU stock: 2.54% gain on August 3, 2020
IMO stock: 2.11% gain 
CNQ stock: 0.68%
HUSKF:   -3.43%
CVE: 2.91%
PPL: -0.15%

So those positions should have gain: $500 dollars



Ameritrade.com: My key largo update

August 3, 2020

Introduction

It is a holiday in British Columbia. I like to take some time to thank my employer and also I have luxury to play with stock market, as a beginner, I lost $3000 to $4000 in the stock market since June 5, but I learned to hold valuable stocks. 

My key largo


Here's What We Like About Intel's (NASDAQ:INTC) Upcoming Dividend

Here is the article. 

Here are highlights:
  1. Intel's next dividend payment will be US$0.33 per share
  2. Last year, in total, the company distributed US$1.32 to shareholders.
  3. Calculating the last year's worth of payments shows that Intel has a trailing yield of 2.8% on the current share price of $47.73.
  4. Intel has a low and conservative payout ratio of just 23% of its income after tax.
  5.  Thankfully its dividend payments took up just 25% of the free cash flow it generated, which is a comfortable payout ratio.
  6. Intel's earnings per share have risen 18% per annum over the last five years.
  7. It's encouraging to see the company lifting dividends while earnings are growing, suggesting at least some corporate interest in rewarding shareholders.

Things I learn to read the article:
  1. How to calculate trailing yield
  2. Gather all financial information about Intel

Intel Corporation (NASDAQ:INTC) stock is about to trade ex-dividend in three days. Ex-dividend means that investors that purchase the stock on or after the 6th of August will not receive this dividend, which will be paid on the 1st of September.

Intel's next dividend payment will be US$0.33 per share. Last year, in total, the company distributed US$1.32 to shareholders. Calculating the last year's worth of payments shows that Intel has a trailing yield of 2.8% on the current share price of $47.73. Dividends are a major contributor to investment returns for long term holders, but only if the dividend continues to be paid. So we need to check whether the dividend payments are covered, and if earnings are growing.

Check out our latest analysis for Intel

Dividends are typically paid out of company income, so if a company pays out more than it earned, its dividend is usually at a higher risk of being cut. Intel has a low and conservative payout ratio of just 23% of its income after tax. A useful secondary check can be to evaluate whether Intel generated enough free cash flow to afford its dividend. Thankfully its dividend payments took up just 25% of the free cash flow it generated, which is a comfortable payout ratio.

It's encouraging to see that the dividend is covered by both profit and cash flow. This generally suggests the dividend is sustainable, as long as earnings don't drop precipitously.

Click here to see the company's payout ratio, plus analyst estimates of its future dividends.

Have Earnings And Dividends Been Growing?

Businesses with strong growth prospects usually make the best dividend payers, because it's easier to grow dividends when earnings per share are improving. Investors love dividends, so if earnings fall and the dividend is reduced, expect a stock to be sold off heavily at the same time. For this reason, we're glad to see Intel's earnings per share have risen 18% per annum over the last five years. Earnings per share have been growing rapidly and the company is retaining a majority of its earnings within the business. This will make it easier to fund future growth efforts and we think this is an attractive combination - plus the dividend can always be increased later.

Many investors will assess a company's dividend performance by evaluating how much the dividend payments have changed over time. Since the start of our data, 10 years ago, Intel has lifted its dividend by approximately 9.0% a year on average. It's encouraging to see the company lifting dividends while earnings are growing, suggesting at least some corporate interest in rewarding shareholders.

Final Takeaway

From a dividend perspective, should investors buy or avoid Intel? Intel has been growing earnings at a rapid rate, and has a conservatively low payout ratio, implying that it is reinvesting heavily in its business; a sterling combination. It's a promising combination that should mark this company worthy of closer attention.

With that in mind, a critical part of thorough stock research is being aware of any risks that stock currently faces. To help with this, we've discovered 2 warning signs for Intel that you should be aware of before investing in their shares.

A common investment mistake is buying the first interesting stock you see. Here you can find a list of promising dividend stocks with a greater than 2% yield and an upcoming dividend.



Facebook/LinkedIn面试官亲授:硅谷“两大巨头”,究竟如何面试?

Here is the link. 

在Facebook面试超过50人的Jim老师,在LinkedIn面试超80人的Jeff老师,拥有“面人”超级丰富的经验。他们逐条分析,两大“硅谷巨头”如何面试?添加微信(orangechaser)加入BitTiger求职内推群。

1:20/ 2:17

Linkedin system design interview tips



Time range: 1:12 - 1:14 /2:17





How to prepare for interview from hiring manager? Based on how the report is written by hiring manager. 

How to present the talent to manage projects at work? 
How do you manage those problems at project? 
Time estimation, coordination, ...
a problem, present a solution - how to manage the project? 
Life cycle of project, how users will use, and then have a product manager thinking as an engineer. 

How to design product feature to enhance competitions? 

BitTiger: Lyft Manager袁林:如何高效准备软件工程师(Software Engineer)面试?

Here is the link. 

-看中求职者身上什么能力? -面试中怎么present自己的项目最“吸睛”? -Behaviro question怎么答? -面试中遇到不会回答的问题,怎么答不丢分? -对转专业的面试者有Bias吗?


Behavior questions:

Projects:

Project design:


Sunday, August 2, 2020

bitTiger: Load balancer - presentation in Chinese

Here is the link. 

OSI Layer - Protocol data unit (PDU)

Data
TCP/UDP
IP
Mac
Bit

Load balancer: 

Application Delivery Controller/ Network (ADC/ ADN)

Load balancing algorithm:  round robin 

My study notes:

I just could not believe how good the presentation is, and I learned a few things. It is interesting to see how load balancer is configured in a small program. 





 

System design: Websocket and REST

August, 2020

Introduction

It is a very good topic for me to learn quickly. I do think that the comparison between websocket and REST is the start for me to ask questions, and build strong curiosity in learning networking, HTTP protocol, application layer. 

Ten difference

I just copy the content from the article here

Both  are popular choices in the market; let us discuss some of the major difference :

  1. WebSocket is a low-level protocol, based on the concept of socket and port, which are the underlying transport mechanism whereas REST is based on CRUD operation.
  2. WebSocket require the use of IP address and Port details, which are lower level details for any application whereas RESTful application needs to design operation based on verbs, and HTTP based.
  3. WebSocket is bi-directional in nature i.e. both way operation from client to server and vice versa is possible whereas REST follows a uni-directional approach.
  4. WebSocket approach is ideal for real-time scalable application, whereas REST is better suited for the scenario with lots of getting request.
  5. WebSocket is a stateful protocol whereas REST is based on stateless protocol i.e. client does not need to know about the server and same hold true for the server.
  6. WebSocket connection can scale vertically on a single server whereas REST, which is HTTP based can scale horizontally.
  7. WebSocket is ideal for a scenario where high loads are a part of game i.e. real-time scalable chat application whereas REST is better fitted for occasional communication, in a typical GET request scenario to call RESTful APIs.
  8. WebSocket works better, where client-server communicates over the same TCP connection for the life of web socket connection whereas, for HTTP request, a new TCP connection is initiated.
  9. WebSocket communication allows client and server to talk independently of each other whereas with the REST based approach, either client is talking to the client or server is talking to the client at any given time.
  10. WebSocket communication cost is lower whereas REST-based communication is comparatively higher end on the cost.

Websockets vs REST API

The idea behind a socket, is that it is a “port” through which data goes in and out of. Much like a real trading port for data, the socket itself is like the dock, it’s where exchanges are happening from the application standpoint. The socket itself is abstract and low level, and staying with the metaphor, many different ships, trains, and equipment can use it. We can call all of these Protocols.

On the Internet there are hundreds of protocols, but a few stand out as the most common, like HTTP, FTP, SMTP, POP3, etc. and lower level transport protocols like TCP and UDP. In essence, Protocols determine how to interpret the data going to and from the socket and the machines that are communicating with each other.


What are WebSockets?

WebSockets are really just an extension of the socket idea. While HTTP was invented for the World Wide Web, and has been used by browsers since then, it had limitations. It was a particular protocol that worked in a particular way, and wasn’t well suited for every need. In particular was how HTTP handled connections. Whenever you made a request, say to download html, or an image, a port/socket was opened, data was transferred, and then it was closed.

The opening and closing creates overhead, and for certain applications, especially those that want rapid responses or real time interactions or display streams of data, this just doesn’t work.

Case study: mock interview - construct binary tree from post order and inorder traversal lists

Here is the link of transcript. 

Start of transcript

End of transcript


System design: From a novice to an expert in less than 10 days

August 2, 2020

Introduction

It is the interviewee's dilemma, if I cannot pass the phone screen, then I should focus on algorithm and data structure; After the phone screen, there is less than 2 - 3 weeks to prepare system design, and also algorithm practice. How should I make myself an expert on system design interview? Can I make transition from a novice to an expert. 


Domain sharding on the modern web

Here is the article. 

Another interesting limit is that browsers have a total limit of concurrent connections regardless of the number of different hostnames used. This can be a major reason against domain sharding, if you consider that some browsers only support 10–17 requests max in any case.

Domain sharding is not as useful for sites with mostly static assets that do not change often, because they will get cached in the browser’s cache. The user will still feel the impact on the first load. You will get further by pushing down less Javascript, CSS and other assets to your users by making use of techniques like code-splitting, but that is a topic for another post.

Investigate where in your web app or site you are actually running into assets which are being queued because of the browser’s concurrent call limitation. It might not actually be a problem. Then, first try to reduce the number of assets before deciding on using domain sharding.

Study notes:

browser’s concurrent call limitation
reduce the number of assets before deciding on using domain sharding ...
being queued - app or site 
static assets - browser's cache 
impact on first load 
code-splitting vs domain sharing on the modern web - Spend 10 minutes to look into code-splitting





Introduction to HTTP/2

Here is the article. 

I plan to read the article when I have 10 minutes to spend. 


Comet, Ajax Push, Reverse Ajax, Two-way-web, HTTP Streaming and HTTP server push

Here is the wiki article. 

Google added web-based chat to Gmail
JotSpot, a startup since acquired by Google, built Comet-based real-time collaborative document editing.[23] 
New Comet variants were created, such as the Java-based ICEfaces JSF framework (although they prefer the term "Ajax Push"[5]). 
Others that had previously used Java-applet based transports switched instead to pure-JavaScript implementations.[24]

Google Docs? - HTTP server push?

Google added web-based chat to GmailJotSpot, a startup since acquired by Google, built Comet-based real-time collaborative document editing.[23] New Comet variants were created, such as the Java-based ICEfaces JSF framework (although they prefer the term "Ajax Push"[5]). Others that had previously used Java-applet based transports switched instead to pure-JavaScript implementations.[24]

My notes:
Polling - two-way sustained interaction, persistent or long-lasting HTTP connection
page-by-page web model? 

Comet applications attempt to eliminate the limitations of the page-by-page web model and traditional polling by offering two-way sustained interaction, using a persistent or long-lasting HTTP connection between the server and the client.

traditional polling? 
two-way sustained interaction? 
persistent or long-lasting HTTP connection? 

many Comet applications use long polling, which is easier to implement on the browser side, and works, at minimum, in every browser that supports XHR.

XMLHttpRequest long polling



Streaming and long polling

Streaming - hidden iframe
XMLHttpRequest 
Ajax with long polling 

Actionable Items


Ask more questions first. And then go back to read networking lecture notes related to application layer and network layer

Push technology, server push - internet based communication

Push technology, or server push, is a style of Internet-based communication where the request for a given transaction is initiated by the publisher or central server. It is contrasted with pull/get, where the request for the transmission of information is initiated by the receiver or client.

Push services are often based on information preferences expressed in advance. This is called a publish/subscribe model. A client "subscribes" to various information "channels" provided by a server; whenever new content is available on one of those channels, the server pushes that information out to the client.

Push is sometimes emulated with a polling technique, particularly under circumstances where a real push is not possible, such as sites with security policies that require rejection of incoming HTTP/S requests.


Traders: Millions by the Minute - BBC Two

Movie and investor CNBC hostess - Karen Finerman

I like to look into those keywords:

  1. 厌恶损失的人类天性并没有在交易年岁上或者补偿
  2. 三类典型的交易特征:交易量过少,无法获得盘感,出局;交易量过大,交易冲动过多,没有慎重思考,出局;管理自己的钱和代理别人的钱,承担风险的欲望不同。


在网上看ichimoku指标晕头转向时,发现了《交易员》视频,本着放松的初衷看了一集。真是真实生活的写照啊。那些人,没有笑脸的,除了盈利时露出一丝会意的笑容——“我对了!”。大多数时候,他们是严肃的、紧张的、面无表情的、甚至沮丧的。是的,亏损时,自然很沮丧。盈利时,如果跑的比别人慢,也没有那么的愉快啊~~


但这些不是重点,重点是不同交易**赋予**的生活模式。对,《我生活的种种模式》。他不是西蒙有目的的每隔几年切换工作方向的模式。而是反过来,几十年市场变动后,让交易员将自己的生活模式与交易模式相契合的结果。


片中的对冲基金经理,那个**双**双胞胎妈妈,她是一个价值投资者,换言之,她buy low,and sell high。她并不**很**在乎每天市场的波动,而更关注那些长期影响股票价值,以及突发事件对股票的影响。她辨别价值和噪音,从而将精力从每日的波动中解放出来。她大概是几个人中生活得比较有质量的人。可以去参加慈善party,可以有空享受孩子和老公的环抱。不过看到她走过彩打出不同孩子time schedule的区域,坐在凳子上微微皱起眉头,烦恼地看着家里的宠物狗时,我真的想开怀大笑。就连她的喜好也和我同出一辙,烦躁时唯有看看书,才能有所收获。她的想法,家里要宽敞一点儿,也是我的偏好。毕竟工作时考虑那么多,回家后如果脑子不能放空,屋子里空一些也好......


我真的跟她很有共鸣。


日内交易者的痛苦就很明显了。片中的老交易员,也会失手。在前一个交易损失后,明明知道后一个交易在获利,也会急于close掉,以获得对前一个损失补偿的心理效果。厌恶损失的人类天性并没有在交易年岁上或者补偿。他们可以很明确的说出三类典型的交易特征:交易量过少,无法获得盘感,出局;交易量过大,交易冲动过多,没有慎重思考,出局;管理自己的钱和代理别人的钱,承担风险的欲望不同。但除此之外,10个人入局的6个人,还有其他一些什么特征,就没有再接着阐述了。


高频交易商一脸苦相的出现在镜头里,他知道自己不受人待见,所以很诚恳地站在一大排服务器前,说出了一项事实。如果我把这些我珍爱的,每个都起了名字的服务器关掉,明天你们买卖的价格很可能不会更好。


是的,高频交易/算法交易现在是最受争议和发展最快的领域。散单无疑创造了一些流动性,但闪单则是截胡策略。在以百万分之一秒为单位交易的世界里,人类没有办法超过机器的执行能力。片中两个场内交易商选择黯然退场,去找寻其他轻脑力劳动的工作。


但是,人类不是适应性动物吗?为什么西蒙可以转换自如?但是在金融这个行业里,转换单一子类工种都那么困难呢?世界变化了,我们为什么不能选择适应它?


不是绝对不能,但属于相对不能。


我们都是被时空局限的人类。一个人高度注意的时间是有限的。在高度运转的世界里呆久了,没有时间没有**心流**去学习更新自己。片中可以看到,在这个领域里,每个人都定型了。连最有时间思考,闭市后脑海里没那么多心思考虑自己头寸压力的女对冲基金经理,看到家里的宠物狗时,都不是一种放松的心情。那种表情,是一种忧虑、烦躁、恨不得get rid of that的样子。不是我们选择了生活方式,而是这个行情选择了我们自己。


所以每个人都在他初始设定的轨道下进行下去。路径依赖越来越明显。


或迟或早,你总会找到属于自己的pattern。但这个pattern不完全是由你自己的意愿决定的。交易者要形成2个系统。一个系统是处理你的注意力系统。在集中大量脑力之后,能不能有更多的精力用来跟踪市场的科技发展,让你从场内做市商,成功转换到高频做市商呢?没有那么容易的事情。另一个系统是你的情绪系统。你要学会热爱你的职业。如果你不热爱它,你就不能自觉自愿地从一个生手转换为熟手。你还不能太热爱它。让你丧失为人的另一大乐趣:家庭生活。


如果你意识到这两个系统,在已经很忙碌的交易时间驱动后,找到自己的创造者时间,你就能用它平衡自己的心理局限,找到更为舒适的人生。

Individual investor - most important is sentimental management


心态比技术更重要

1、大多数散户犯的最大的错误之一,就是缺乏纪律性,你必须有条不紊,提前做好方案,然后等待市场的考验,那么多交易员不幸亏钱,原因就在于此。


2、很多散户一直在看多,认为它会涨涨涨,所以他们会因为看错方向而被套牢,他们总是站在市场错误的一边,而我想站在另一边,因为大众通常都是错的。


3、大多数新手总是想着他们能赚多少钱,而专业的交易员,会着眼于可能会亏多少钱,这是一个简单的成功法门,但令人惊讶的是,既然有那么多人会犯这个错误。


4、我虽然在外面,但是我已经做好了分析,并做好了执行方案,单子已经提交了,让他们自动执行就行了,这就是风险与回报的问题了,我要么亏2个点,要么赚6个点,就这么简单。


5、说到交易,你要么赚钱要么赔钱,那为什么很多人赚不到钱呢,这并不是技术能力的问题,随着时间的推移,你会逐渐获得技术能力。但你还要面对回吐的问题,交易中会遭遇巨额的回吐,很多人会觉得自己没办法承受而选择放弃,大多数选择放弃的人,可能并没有付出自己最大的努力吧.



Long polling -> system design -> networking course -> go back to long polling article

August 2, 2020

Introduction

It is the first time I realize that it is so powerful tool I should master last 10 years. What I did miss is to review those networking and distribute system courses on the internet regularly. It will make me an excellent engineer and learner any where and any time. 

My system design reading task

I have to focus on the basics this time.  I do believe those course lecture notes are so good for me to learn and review basics, and then get back to those topics like long polling I worked on before. The article I read should be perfect match to examine how good I learn through those lecture notes. 

Long polling article is here


Camila Cabello - Easy (Live on SNL)

Here is the link. 


Forbes: #39 Shawn Mendes

  • The singer-songwriter grossed $87 million on tour in 2019, slightly more than the Jonas Brothers and a bit less than Post Malone.
  • Mendes is barely old enough to buy a beer and has endorsement deals with the likes of Calvin Klein.
  • His music moved over 1 million album-equivalent units during our 12-month scoring period.

Saturday, August 1, 2020

24 Hours With Hailee Steinfeld | Vogue

Here is the link. 


Hailee Steinfeld Net Worth

Here is the detail:

Hailee Steinfeld net worth: Hailee Steinfeld is an American television and film actress who has a net worth of $8 million. Born December 11, 1996 in Tarzana (Los Angeles), California, the teen actress rose to fame for her role in (remake) True Grit (2010) as Mattie Ross, for which she received award nominations, including an Academy Award nomination for Best Supporting Actress, SAG Award (Screen Actors Guild) for Outstanding Performance by a Female Actor in a Supporting Role and BAFTA Award (British Academy of Film and Television Arts) for Best Actress in a Leading Role. She began her acting career at age eight when she played the role of Talia Alden in the award-winning short film She's a Fox. Before being chosen (out of 15,000 girls) for the role of Mattie Ross in True Grit, Steinfeld was cast in several television commercials and made guest appearances on others. In May 2011, she was named as the 'new face' of Italian designer brand Miu Miu. She was cast in the role of Juliet Capulet in a 2013 adaptation of Shakespeare's Romeo and Juliet. Because she was only fourteen when cast in the role of Juliet, the love scenes and nudity were removed from the script to make it age-appropriate for the young actress. In early 2014, Steinfeld narrated (as the voice of Anne Frank) for an exhibition on Anne Frank at the Museum of Tolerance, Los Angeles, California. Steinfeld's older brother, Griffin, is a NASCAR driver, her paternal uncle is fitness trainer Jake Steinfeld and her maternal great-uncle is former child actor Larry Domasin.


Leetcode discuss: 106 Construct Binary Tree from Inorder and Postorder Traversal

Here is the link. 

C# practice to prepare FANG onsite 2020

August 1, 2020
106 Construct Binary Tree from Inorder and Postorder Traversal
Assume that all nodes have distince value, construct binary tree from inorder and postroder traversal.

Introduction

It is tough decision for me to work on system design, reading networking and operation system lecture notes. I did not have time to practice algorithm after phone screen. This is the first algorithm I wrote after break from July 20. I have two more weeks to practice algorithm.

Algorithm case study
Quick review, inorder traversal is left child, root and right child whereas post order traversal is left child, right child and root node.

Example:
[9, 3, 15, 20, 7] - inorder
[9, 15, 7, 20, 3] - postorder
It is easy to find root node by post order traversal. Last node of postorder traversal is the root node, the example tree is root node with value 3. Next go through inorder traversal hashmap, rootnode 3 has index value 1. So left subtree has subarray [9], right subtree has subarray [15, 20, 7] inorder traversal. Also left subtree's length is 1, right subree length is 3.

Next it is to work on post order traversal list. First part is left subtree, knowing start index and length; Next part is right subree and length of subtree.

Highlights of my practice

  1. Work on test case given in the above, and then try to write simple code;
  2. If the left subtree is empty, then the subarray's start and end index will have contraction: endIndex < startIndex;
  3. Work on length of left subtree and right subtree;
  4. Be patient. I came cross the time limit exceeded. So I started to test code using the above test case, and found two places to fix.
  5. Trust the example test case is good enough to write bug-free code. Go through step by step.
/**
 * 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 {
    // [9, 3, 15, 20, 7] - inorder
    // [9, 15, 7, 20, 3] - postorder
    //
    public TreeNode BuildTree(int[] inorder, int[] postorder) {
        if(inorder == null || postorder == null || inorder.Length != postorder.Length || inorder.Length == 0)
        {
            return null; 
        }
        
        // the idea is to find root node from post order, step 1;
        // use root node to look up inorder traversal, and then find root node, step 2;
        // Based on the above two steps, left subtree array is defined by start and end index, same as right subtree
        var map = new Dictionary<int, int>(); 
        for(int i = 0; i < inorder.Length; i++)
        {
            map.Add(inorder[i],i);
        }
        
        return runRecursiveSolution(inorder, 0, inorder.Length - 1, postorder, 0, postorder.Length - 1, map);        
    }
    
   // [9, 3, 15, 20, 7] - inorder
    // [9, 15, 7, 20, 3] - postorder
    // inorder
    // left subtree - [9]
    // right subtree [15, 20, 7]
    //
    // postorder
    // left subtree - knowing the length is 1
    // [9]
    // right subtree
    // [15, 7, 20]
    // how to express empty tree? 
    // how to express empty left/ right subtree using index?
    // define endIn < startIn or startPost < endPost - make it simple
    private TreeNode runRecursiveSolution(int[] inorder, int startIn, int endIn, int[] postorder, int startPost, int endPost, Dictionary<int, int> map)
    {
        // base case ?        
        if(startIn > endIn || startPost > endPost)
            return null;
        
        var rootValue = postorder[endPost];         
        var root = new TreeNode(rootValue);        
        
        var inorderIndex = map[rootValue]; // 1
        
        // left subtree - inorder list before root node
        var leftCount = inorderIndex - startIn;         
        
        var endPostNext = startPost + leftCount -1;
        
        // if left subtree is empty, then inorderIndex - 1 < startIn
        root.left = runRecursiveSolution(inorder, startIn, inorderIndex - 1, postorder, startPost, endPostNext, map);
        
        // right subtree - inorder list after root node
        var rightStart = endPostNext + 1;  // should be +1, not +2
        //var rightCount = endPostNext - startPost + 1; 
        var rightCount = endIn - inorderIndex; // calculate by inorder list 
        
        root.right = runRecursiveSolution(inorder, inorderIndex + 1, endIn,                                          
        postorder, rightStart, rightStart + rightCount - 1, map);        
        
        return root;               
    }
}

IMO.TO stock: Imperial Oil (IMO) Reports Q2 Loss, Misses Revenue Estimates

Here is the article. 

Facts to review:
  1. IMO.TO a quarterly loss of $0.52 per share, estimation $0.69 per share; $0.66 earning a year ago


Original article:

Imperial Oil (IMO) came out with a quarterly loss of $0.52 per share versus the Zacks Consensus Estimate of a loss of $0.69. This compares to earnings of $0.66 per share a year ago. These figures are adjusted for non-recurring items.

This quarterly report represents an earnings surprise of 24.64%. A quarter ago, it was expected that this oil and gas and petroleum products company would post a loss of $0.02 per share when it actually produced earnings of $0.05, delivering a surprise of 350%.

Over the last four quarters, the company has surpassed consensus EPS estimates two times.

Imperial Oil, which belongs to the Zacks Oil and Gas - Integrated - Canadian industry, posted revenues of $2.68 billion for the quarter ended June 2020, missing the Zacks Consensus Estimate by 13.26%. This compares to year-ago revenues of $6.92 billion. The company has topped consensus revenue estimates just once over the last four quarters.

The sustainability of the stock's immediate price movement based on the recently-released numbers and future earnings expectations will mostly depend on management's commentary on the earnings call.

Imperial Oil shares have lost about 38.3% since the beginning of the year versus the S&P 500's gain of 0.5%.


Facts to review:


Original content:

What's Next for Imperial Oil?

While Imperial Oil has underperformed the market so far this year, the question that comes to investors' minds is: what's next for the stock?

There are no easy answers to this key question, but one reliable measure that can help investors address this is the company's earnings outlook. Not only does this include current consensus earnings expectations for the coming quarter(s), but also how these expectations have changed lately.

Empirical research shows a strong correlation between near-term stock movements and trends in earnings estimate revisions. Investors can track such revisions by themselves or rely on a tried-and-tested rating tool like the Zacks Rank, which has an impressive track record of harnessing the power of earnings estimate revisions.

Ahead of this earnings release, the estimate revisions trend for Imperial Oil was mixed. While the magnitude and direction of estimate revisions could change following the company's just-released earnings report, the current status translates into a Zacks Rank #3 (Hold) for the stock. So, the shares are expected to perform in line with the market in the near future. You can see the complete list of today's Zacks #1 Rank (Strong Buy) stocks here.

It will be interesting to see how estimates for the coming quarters and current fiscal year change in the days ahead. The current consensus EPS estimate is -$0.01 on $3.79 billion in revenues for the coming quarter and -$1 on $17.64 billion in revenues for the current fiscal year.

Investors should be mindful of the fact that the outlook for the industry can have a material impact on the performance of the stock as well. In terms of the Zacks Industry Rank, Oil and Gas - Integrated - Canadian is currently in the top 19% of the 250 plus Zacks industries. Our research shows that the top 50% of the Zacks-ranked industries outperform the bottom 50% by a factor of more than 2 to 1.