From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
Saturday, August 1, 2020
Hailee Steinfeld Net Worth
Leetcode discuss: 106 Construct Binary Tree from Inorder and Postorder Traversal
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
- Work on test case given in the above, and then try to write simple code;
- If the left subtree is empty, then the subarray's start and end index will have contraction: endIndex < startIndex;
- Work on length of left subtree and right subtree;
- 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.
- 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
- IMO.TO a quarterly loss of $0.52 per share, estimation $0.69 per share; $0.66 earning a year ago
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.
AC.TO stock: Air Canada
IMO.TO stock: My weekend research on August 1, 2020
Actionable Items
Follow up
TSX stocks: Most actively traded companies on the TSX
IMO.TO stock: Imperial declares third quarter 2020 dividend
Imperial Oil Limited today declared a quarterly dividend of 22 cents per share on the outstanding common shares of the company, payable on October 1, 2020, to shareholders of record at the close of business on September 4, 2020.
This third quarter 2020 dividend compares with the second quarter 2020 dividend of 22 cents per share.
Actionable Items:
Suncor stock: Suncor (TSX:SU) CEO Has This Warning to Share
August 1, 2020
Introduction
I am nervous as a beginner investor. I just put $45,000 Canadian dollars in the market, since I made a mistake less than two weeks ago and sold 2000 shares of HSE.TO because of panic, I like to go over the same process again and relearn the lesson.
One article helps panic mind to think ....
The demand hasn’t reached its full capacity yet, and it might slump again if another wave of the pandemic hits. And that’s just one of the reasons why Suncor is continuing with its limited production capacity. The company produced about 18.5% less oil per day in the second quarter of 2020 than it did in the second quarter last year.
The CEO expects prices to remain volatile, though not as much as they were in the second quarter. Still, the company will not take the decision of reopening its second train in its Fort Hills facility if the demand stays steady or grows. But he also listed factors (including a second wave of the pandemic) that might instigate another bout of low demand.
Suncor’s stock
The company is currently trading at $21.5 per share at writing. It’s about half the pre-pandemic highest. The company is also facing seven environmental charges, and the company recently posted a loss of $614 million for its second quarter.
That’s a massive sink from the $2.7 billion profit in the same quarter last year. This beloved Dividend Aristocrat also had to slash its dividend down to 50% of its previous year’s dividends.
The energy sector is suffering, and Suncor is suffering a bit more than many other companies in the energy sector. If the company has to keep operating at low capacity and demand doesn’t surge for a few more months, we might see one or two more quarters of loss.
Foolish takeaway
At its current valuation, Suncor might look very attractive to some investors. Even after slashing its dividends down to halves, the yield is at 3.9%. The stock is trading at a price to books of 0.9 and a trailing price to earnings of 12 times.
While the balance sheet is strong, the prospects appear dark. But Buffett hasn’t bailed on the company yet, and that might be a good sign.
The post Suncor (TSX:SU) CEO Has This Warning to Share appeared first on The Motley Fool Canada.
Facts to review:
- Suncor produced about 18.5% less oil per day in the second quarter of 2020 than it did in the second quarter last year.
- Suncor will not take the decision of reopening its second train in its Fort Hills facility if the demand stays steady or grows.
- Buffett hasn’t bailed on the company yet, and that might be a good sign.
- If the company has to keep operating at low capacity and demand doesn’t surge for a few more months, we might see one or two more quarters of loss.
- The company is currently trading at $21.5 per share at writing. It’s about half the pre-pandemic highest. The company is also facing seven environmental charges, and the company recently posted a loss of $614 million for its second quarter.
Actionable Items
Friday, July 31, 2020
Stanford university: CS144 – Introduction to Computer Networking
Stock purchase: My purchase of TFSA and Key largo portfolio
Introduction
Analysis and my monthly plan on August 2020
My business plan
Actionable items
Exxon, Chevron Earnings Gutted by Virus-Driven Demand Slump
Exxon Mobil Corp. and Chevron Corp. posted the worst losses in a generation after the pandemic and a global crude glut combined to batter almost every part of their businesses.
Exxon’s $1.1 billion second-quarter loss was the deepest in the company’s modern history. A collapse in crude prices bled the company’s production division while Covid-19 lockdowns lowered demand for everything from jet fuel to plastic wrap, hobbling the company’s refining and chemical units.
Chevron recorded its weakest performance in at least three decades and warned that the global pandemic wreaking havoc upon energy markets may continue to drag on earnings. The explorer plans to curtail the equivalent of 5% of its worldwide output during the current quarter and backtracked on plans to massively ramp up production from its prized Permian Basin holdings.
Oil has become the poorest-performing sector of U.S. equity markets as a confluence of economic, political and structural threats coalesce to imperil the very foundations of the petroleum industry. Sweeping layoffs, budget cuts and project cancellations haven’t been enough to arrest the industry’s decline as fleeing investors made energy the worst investment in the S&P 500 Index this year.
Without the massive trading operations that shielded European oil explorers such as Royal Dutch Shell Plc and Total SE from losses, Chevron was exposed to the full force of this year’s oil price rout. Notably, Exxon’s nascent trading foray “experienced unfavorable mark-to-market derivative impacts,” the company said.
Exxon generated zero cash from operating activities during the quarter, according to a statement on Friday.
Actionable Items
Buy some Exxon stock.
Big Tech Got Bigger, Big Oil Got Smaller During Virus Lockdown
Thursday, July 30, 2020
More distributed courses please!
Introduction
System design preparation
AMD stock: 50% return July 2020 - I missed it!
Introduction
My AMD stock research
CVE stock: Probability analysis
- There is a chance for second crash in short future. No one can avoid market risk;
- The lowest price is 5.89. Should I wait for the price? Or I just go for 6.09?
- How much should I take risk? Should I purchase 10,000 shares or 1000 shares?
- Market swing is the chance to make 10% return.
- Admit that I am a beginner. Try to survive longer. I save those TFSA funds over 10 years.
- Be patient. Do not gamble! Take some risk as well.
GE post $2 billion loss as jet engine orders sink
General Electric Co. posted a roughly $2 billion quarterly loss as revenue tumbled 24%, hurt by a steep decline in a jet-engine business that has been hobbled by the coronavirus pandemic.
The aviation business, once a profit engine for GE, swung to a loss in the June quarter as both revenue and orders plunged. The unit produces engines for Boeing Co. and Airbus SE planes but has had to cut production and jobs as airlines delay orders. On Wednesday, Boeing said it would cut further production of commercial jets.
GE reported it burned through less cash in the June quarter than it had previously warned. The company reported adjusted negative cash flow from industrial operations of $2.1 billion, compared with its projection of negative $3.5 billion to $4.5 billion in May. Analysts were expecting negative cash flow of $3.29 billion, according to FactSet.
"We're working through a still-difficult Covid-19 environment," said CEO Larry Culp, adding that he still expected a prolonged recovery for the commercial-aviation business. "Still, based on what we see today and the actions we've taken, sequential improvement in earnings and cash in the second half of the year is achievable."
Umich.edu: Introduction to distributed system
- Resource sharing
- Device sharing
- Flexibility to spread load
- Incremental growth
- Cost/performance
- Reliability/Availability
- Inherent distribution
- Security?
University of Waterloo: Distributed Database
HSE.TO stock: Husky Energy swings to $304-million loss in Q2 as revenues plunge
CALGARY — Husky Energy Inc. swung to a $304-million net loss in the second quarter as revenues plunged nearly 55 per cent.
The Calgary-based oil producer says it lost 31 cents per diluted share for the three months ended June 30, compared with net income of 36 cents per share or $370 million a year earlier.
Revenues were $2.38 billion, down from $5.24 billion in the second quarter of 2019.
Husky Energy was expected to lose 39 cents per share on $2.73 billion of revenues, according to financial markets data firm Refinitiv.
Funds from operations were $18 million or two cents per share, down from $802 million or 80 cents per share a year earlier while capital expenditures were $310 million, including $63 million in Superior Refinery rebuild capital.
Total equivalent production fell 7.8 per cent to 247,000 barrels of oil equivalent per day, from $268,000 a year earlier.
Facts to review:


















