Friday, October 25, 2019

How to retire at the age of 40? ETF

2、ETF
标准普尔500指数在近20多年里的平均回报是8%多一点点,但波动如过山车一般。在这漫长的5000个交易日里,去掉其中最好的20个交易日,这个数字就变成4%左右了。再去掉20个,就是2%不到了。再去掉20个,直接变负数。因此建议选择指ETF而不是具体哪支股票,这样适合长期积累复利。我们听到了太多的“一年翻几倍”的例子,但要知道那些更多的“一年亏到底”的人是不会四处宣扬的。事关退休大计,还是稳妥些好。

Facts:


S & P Index 500%, 8% average annual return 

20 years -> 5000 days -> 20 best days, if those 20 days are removed, 4% return
-> continue to return next best days, return 2% -> another 20 days, return negative. 

Do not time the market. Stay in the market. 


How to retired at the age of 40? Insurance

合理的投资理财,让时间见证复利

通过长时间的投资理财可以积累财富,也可以为提前退休创造经济条件,以下是几种相对稳定的投资手段。

1、保险
美国保险的种类很多,其中不乏兼具投资属性的产品。指数型万能寿险是其中的佼佼者,它是万能险的一个变种。可以挂钩三大指数——美国标普500、香港恒生指数、德国30DAX指数,并且现金值是保本的。就算是指数跌了,现金值也可以得到2%左右的收益。数据显示,美国股票市场过去几十年平均年化收益在7.5%,多数年份有8%至10%左右的收益。

相对来说,这一收益水平要好于仅投资债券市场类保险品种3%至4%的回报。除了同样具备避资本利得税和遗产税的功能之外,客户还可以随时从现金值里借钱出来。最多可以拿到现金值的90%,几乎是零利率而且同样不需要交税。因此它既可以在发生意外时给家人提供保障,又可以当作一个投资账户,在自己退休甚至平时进行大额采购时提取出来。

Facts:

美国标普500、香港恒生指数、德国30DAX指数
美国股票市场过去几十年平均年化收益在7.5%

How Tennis Players Can Cope With Frustration

Here is the link.


Thursday, October 24, 2019

What I learned as a hedge fund manager

Here is the article.


Margin of Safety - Seth Klarman's 10 Rules for Investing Success

Here is the link.


Seth Klarman on Value Investing, Warren Buffett, Ben Graham and more..

Here is the link.


Seth Klarman: How To Achieve A 20% Return Per Year (10 Investing Rules)

Here is the video.

  1. Invest, do not speculate.




Nimble tech firms must adapt as promised self-driving revolution hits speed bumps

Here is the article.

I met an interviewee who is working on self-driving startup in Sillicon Valley, so he told me there are a lot of companies to work on this area.

I like to learn more on this area.




My Samsung S6 maintenance

Oct. 24, 2019

Introduction


It is so interesting to maintain my Samsung S6 mobile phone. I noticed that my mobile phone ran out of storage, so I did the maintenance.

My maintenance


I did connect my phone to my computer, and then removed some downloaded file around 200 MB, and also removed some pictures less than 200 MB.

Now my phone storage has less than 7 GB. I tried to figure out how come 7GB storage is found through those removed files much smaller than 7 GB.




Warmup JavaScript

Oct. 24, 2019

Introduction


I learned from the interviewee from her performance to write word ladder - find all paths. I know that it is time for me to set up a goal to learn JavaScript.

Warm up JavaScript


I learned JavaScript as a functional programming language back in 2014. I spent over 6 months to learn JavaScript in 2014. But it is better to warm up and keep practice to stay updated.

Follow up

Oct. 25, 2019

It is time for me to push myself to improve my coding skills using JavaScript. One of ideas is to work on Leetcode algorithms, and I like to write code using JavaScript instead of C#, and also write Python code instead of C#.

Five easy level algorithms - 441 solved algorithm mark

Oct. 24, 2019

Introduction


It is most important for me to stay humble, and also write C# solutions. Last two months I only solved less than 10 algorithms. Today I solved 5 easy level algorithms.

Crafting skills


It is important for me to learn from easy and simple algorithms first. I know that it will take me a day to solve a hard level algorithm. But it is better for me to solve more algorithms first, work on easy ones, and then move on one medium level,  or one hard level, and then continue to work on easy level ones.

Here is my 441 solved algorithm mark. Let me celebrate the hard work.



Wednesday, October 23, 2019

Steve Siebold and his over 10 books

Oct. 23, 2019

I like to spend time to learn from those books. I like to look into those books.


Ask Linkedin: Why so many startup does not have a proper link?

Oct. 23, 2019


Introduction


I like to look into how to add some links for those startups I worked for on my Linkedin profile. It is so shame to look up my ex-coworkers worked for Siva inc before, all their links went to wrong company or missing information. No one is taking serious on their profile on Linkedin.com.

How to add links? 


I worked for Siva inc which started from 2001 (?) to 2006, and I worked for a startup Trendium, but none of them worked for Trendium can figure out one proper link for the startup, even it had 15 million dollars fund when I joined in 2001. Another three startups I worked for are Daleen technologies Inc, Absolute software, MJA technologies Inc.


Steve Siebold Interview

Here is the link.


9 thoughts holding you back from getting rich — and what to think instead

Here is the link.


  1. I don't deserve to be rich.
  2. I need a master degree to get rich.
  3. Hard work makes me rich - (leverage makes me rich)
  4. Being rich is reserved for a luck few
  5. I have to have money to make money
  6. I just want enough money to retire
  7. I work to make money
  8. ...



7 signs you’ll never be a millionaire

Here is the article.




7 Signs You Will NEVER Be Rich - Avoid These 7 Mistakes

Here is the link.


  1. You focus on too much on saving. Being frugal, cut costs; riches know that it is not enough. Wealth focus on saving and earning. Several streams of income. Rental properties, dividend income. You should be putting just ...
  2. You overspend. You will never be rich if you spend more than you earn. Lack of finance control. Financial management skills. Many people have a hard time to control spending. 
  3. Accept paycheck life style. 
  4. You do not invest your money. Invest index fund, or retirement fund
  5. You do not challenge yourself. 
  6. You do not have financial goals. If you want to amass a million dollars. 
  7. You do not pay yourself first. credit card company, landlord, etc. 10% to yourself every month. 
The rich practices this habit religiously. 

Challenge yourself:
 Jeff Bezo chose to start selling books, leave his high pay investment job.

Financial goals:




The 8 RULES of MONEY

Here is the link.


Wealth transfer in crisis - dot.com bubble
Homeless, jobless, poor

Tuesday, October 22, 2019

Linkedin profile study: one manager a time

Here is the profile.

(According to Levels.fyi, Facebook employees at an E3 ranking earn an average salary of $111,246, with stock options worth roughly $39,649 per year, and a bonus of $18,175. That’s pretty good, and roughly aligns with the data we’re seeing from other sources. By the time they climb to the E7 level, their base salary might total $233,000 per year, with stock options worth roughly $370,000 per year, and a bonus of $58,167.)

Here is the article. 

Linkedin profile study: One manager profile a time

Here is the profile.

Case study: Find median from data stream

Mock interview transcript is here
Transcript ends here


Actionable Items


It is the learning experience for me to be an interviewer on the platform. I have to hold on high standard in terms of passing or not passing the candidate since I had a conversation with the project manager from the platform recently. I asked the second algorithm hard level algorithm, and since the interviewee did not come out the idea to use two heaps - one minimum heap and one maximum heap, I decided not to advance her to next round.

I got some friendly remind to hold on the high standards as other interviewers on the platform. Less than 30% can pass the mock interview.

Case study: Word ladder - find all paths

Oct. 23, 2019

Introduction

It is not a big surprise for me to learn how talent an interviewee can be. I have not written in JavaScript long time, maybe more than two months, and even I write JavaScript, I do not have chance to write a lot of code. I just could not believe that the interviewee wrote bug free code, and it only took her 28 minutes to write everything, and we also had discussion on various topics like time complexity,and all other things.

Case study

I like to play the mock interview again, and then I can learn from the interviewee better after the mock interview. I learn how to perform better as the interviewee did on her mock interview.

Sometimes it is such great learning experience as an interviewer.


Mock interview transcript starts here
end transcript

Facebook onsite interview tips

Here is the article. 

FB的面试主要是 做第1道题 和 做第2道题。第1道题是热身,不会太难。第2道题是正餐,一般难度在Medium左右。要通过面试,第2道题**一定**要做出来. From 1point 3acres bbs

关于题目类型,据我所知FB蛮少考DP,mentor说DP做不出来就是真的做不出来,一点思路都没有,不会被她选做面试题,不利于考察候选人思路。

面试中的tips:
面试官讲完问题之后,可以重复一遍确定自己的理解是否正确,有不清楚的地方要clarify,同时想思路。有时候卡壳可以先从edge case开始,或者反复clarify争取一点时间。有思路之后先给面试官一个high level solution,面试官觉得可行就开始码code. check 1point3acres for more.

码code过程中每写一行尽量阐述那一行码的作用是什么(面试官可能没用过候选人的语言
. check 1point3acres for more.
码完主动口述跑tests,line by line。不仅自己心里有底,让面试官心里也有底XD。自己找bug不扣分,面试官指出来就有一点点虚了

The lazy way to get rich - MoneyWeek Investment Tutorials

Here is the link.

If I study hard, and learn how to get rich, when the opportunity comes, I can recognize them.


WHY the Rich get Richer

Here is the link.



Time to start to work on 68 easy level algorithms

Oct. 22, 2019

Introduction


It is time for me to work on 68 easy level algorithms. I like to warm up my programming skills, and also I like to push myself to work on some basics.

Easy level algorithm

Follow up Oct 24, 2019
I have solved over 200 easy level algorithm so far.


Actionable Items


I like to work on my practice. Ideally I should be able to solve five easy level algorithms in one hour.

As long as I keep continue to write C# code and solve easy level algorithms, I will find out ideas how to solve more algorithms.

It takes courage to be humble, and I like to stay from easy level, and learn from others from easy level problems first.

Most Canadians worry about affording the basics

Here is the link.


From Netflix to Youtube, and then IQIYI

Oct. 22, 2019

Introduction

I like to write a short research how I move from Netflix to youtube.com, and then I start to watch IQIYI.com.


Case study


I went through learning process from entertainment to a learner, and then a acumen learner.

I subscribed Netflix from 2011 to 2016, and then I decided to quit Netflix. In 2018 November, I started to work on youtube.com and learn personal finance by myself. Starting from Oct. 21, 2019, I start to look into IQIYI and see if I can find some Chinese video to watch related to personal finance.


大V开8 : 比尔盖茨推荐的投资秘诀

Here is the link.

天灏资本侯晓天:如何利用AI和另类数据,精准命中Alpha?

Here is the article.

1. Solve 9 tree algorithms first.
2. Solve 68 easy level algorithms next.

Monday, October 21, 2019

老虎说 : 华尔街投资女王给散户的三条军规

Here is the link.

华尔街传奇女性投资专家、天灏资本CEO侯晓天做客《老虎说》,告诉你中股美股到底有何区别,中国散户究竟该怎么操作。

人民币贬值 怎么炒美股让财富保值?

Here is the article.

在人民币的急速贬值之下,全民海外资产配置时代已然加速到来,许多投资者将目光转向美股市场。天灏资本CEO侯晓天曾在华尔街著名机构工作超过15年,她在老虎证券的脱口秀节目《老虎说》采访中表示:美股最大的优势在于交易品种多,中国人投资美股需转变“赌博”心态,并把时间作为一个变量来管理风险。





老虎说 : 走势不利,美股如何掘金?

Here is the link.


老虎说 : 美股还能牛多久?

Here is the link.


老虎说 : A股美股差异在哪

Here is the link.

《金十早知道》 : 美联储降息被指隔靴搔痒,这国意外大降50基点,竟落得如此下场?

Here is the link.


《金十早知道》 : 美国国债倒挂,美联储仍不愿“牺牲”美元,欧洲货币劫数难逃?

Here is the link.


小司聊理财 : 钱存银行怎么存

Here is the link.

I learn that iqiyi is very good stock and I like to look into the website.




Loss Aversion

6、亏损厌恶症
  厌恶亏损(Loss Aversion)是人之常情,A股为甚:卖亏损股票,老外叫Stop Loss(止损),咱们叫割肉断腕——厌恶之情溢于言表;不少人股票涨回成本时就抛,亏损就扛着,还自欺欺人说不卖就不算真的亏。其实,股票的投资价值,与买入成本无关;该不该卖,也与你是否亏损无关。
  1万元亏损带来的痛苦是1万元盈利带来的喜悦的2倍。求稳怕亏体现在机构身上是周期股再便宜也不买,稳定类的股票再贵也拿着,尽管牛市中周期股常领涨;体现在散户身上是28万亿现金存银行,尽管股市长期跑赢现金是不争的事实。

Over-extrapolation - 投资者常见的13个心理误区

5、短期趋势长期化
  某公司利润去年6毛,今年7毛;故意报成去年5毛,今年8毛,增长60%,于是市盈率大涨,这就是利用人性中易把短期趋势长期化的倾向,行为金融学称为Over-extrapolation(过度外推)。把过去的增长过度外推到未来,把不可持续当作可持续,是成长股陷阱和周期股陷阱的共性。

Anchoring Bias - 投资者常见的13个心理误区

4、锚固偏见
  常有人说,这股票涨这么多了,还不抛?或,已经跌一半了,还不买?这就是锚固偏见(Anchoring Bias)的表现,其潜意识是把原有股价当成合理、当成参照的锚点了。其实,一个股票便宜与否,看估值比看近期涨跌更可靠:基本面大幅超预期时可越涨越便宜,反之可越跌越贵。
  Anchoring Bias是奢侈品的常用营销手段。先设计一批2万美元的包包让模特们背着走来走去,让你感觉这个品牌的包就值2万美元一个。这样一来,当你在店里看到1000美元的同一品牌包时,就不觉得贵了。其实,2万美元的包也卖不了几个,利润主要来自于卖1000美元的包。

Confirmation Bias - 投资者常见的13个心理误区

3、仓位思维
  一旦买成了重仓股,对利好就照单全收,对利空消息就不以为然,心理学上叫Confirmation Bias,民间说法叫“屁股决定脑袋”。
  正确的决策流程是先有论据,再有结论;但多数人是先有结论,再找论据,那时对反面的证据自然就视而不见。有了仓位,思维就不客观,故称仓位思维。

How to Get Rich - "The Millionaire Next Door" - An Executive Summary Book Review

Here is the link.


Thomas J. Stanley: The Millionaire Next Door Book Summary

Here is the link.


Sunday, October 20, 2019

Investment books to read

Here is the link. 

1. 在号称30本值得读的投资经典里面:
《漫步华尔街》 (个人非常喜欢这本书)
《聪明的投资者》(巴菲特师傅的经典著作,价值投资的出处)
《股票作手回忆》(娱乐一下,传奇人物的经历,这么厉害的人最后也是破产自杀)
《彼得·林奇的成功投资》(值得一看,传奇人物,而且全身而退,不知道怎么做到的,他说的一些故事很有意思,就是作为普通人,怎么从你的日常生活中,发现一些投资机会,可能比你去研究财报,公司更真实,有效)

2.《投资最重要的事》(这个作者很厉害,可以看看,我也是偶然看到的,我看了觉得写得很好,特别强调风险,敬畏市场)

3. 张化桥,很牛逼的私募基金经理
一个证券分析师的醒悟 张化桥的股市真话
避开股市的地雷 张化桥

4.《投资稳赚 向世界最大基金创始人学稳赚不赔的常识》(The Little Book of Common Sense Investing)
看完下面这本你会对指数基金更加了解,有信心(大家都在市场上面,你能长期战胜市场的概率有多大?)
作者是个很伟大的人,刚刚去世,指数基金之父

Bernier says he doesn't need to be a feminist: 'I believe in people' | Power & Politics

Here is the link.


People's Party of Canada leader Maxime Bernier says Canada needs to have more "economic immigrants"

Here is the link.

Spinning the prospect of a minority government | The Weekly with Wendy Mesley

Here is the link.

Usually, federal leaders refuse to speculate about forming coalitions during the campaign. But with such a tight race, the leaders are publicly negotiating, setting their terms for what might come next, and who they might, or might not play with. The Weekly examines the spin.


Federal Leaders' Debate 2019

Here is the debate I like to spend next two hours to watch.

Marking two weeks from election day, six federal party leaders are set to face off as part of the English-language debate at the Canadian Museum of History in Gatineau, Que.

110 | A Millionaire Next Door Case Study | Rocky Lalvani

Here is the link.


Become The Next Millionaire Next Door! w/ Dr. Sarah Stanley Fallaw

Here is the link.

We are so excited to have our special guest, Dr. Sarah Stanley Fallaw, on The Money Guy Show! In this episode, we are going to talk about millionaire habits, the psychology behind building wealth, and how you can be the next millionaire next door!

Key Ideas From Thomas Stanley's The Millionaire Next Door

Here is the link.


If you invested $1,000 in Chipotle 10 years ago, here’s how much money you’d have now

If you invested in Chipotle 10 years ago, you’d have made a strong profit. A $1,000 investment in 2009 would be worth nearly $8,600 as of July 24, 2019, for a total return of 760%, according to CNBC calculations. By comparison, a $1,000 investment in the S&P 500 would have earned a total return of 280% over the same period.

RICH DAD'S CASHFLOW QUADRANT (BY ROBERT KIYOSAKI)

Here is the link.


Learn to appreciate my belongings

Oct. 20, 2019

Introduction


It is time for me to learn how to value I own. Last week I wear the coat I bought back in 1996. I spent $360 Yuan, 30% of monthly salary in Shanghai. I wear the coat and took picture in 1999 on top of world trade center in New York city.


My fashion show 


I like to take some pictures and demonstrate myself to stay fit, healthy, and also be open to new challenge ahead next 10 or 20 years ahead.




My hair style


It is my idea to save time. I like to cut my hair by myself. I also observe how to maintain the hair style.

How much I can write in 90 minutes?

Oct. 20, 2019

Introduction


It is time for me to evaluate how good I can write in terms of problem solving using C#. I did play weekly contest and then I have to evaluate how good I can write in 90 minutes.

90 minutes


I can write an easy level, one medium level. But I do see top players can write one easy, two medium level, one hard level.

To be a responsible software programmer, I like to train myself hard. If I do not focus, spend time to train myself to solve algorithm problems in C#, I may have problems to face laidoff, unemployment, and also struggle on learning other things, like investment, and lack of learning confidence.

Weekdays and practice


I have to push myself to simulate myself in weekly contest, I should be ready any time to take 90 minutes test, and then write code for 4 algorithms.

If I try one time a day, then I should allow myself to solve 4 algorithm in 8 hours.

If I try this drill over 100 times, I may be able to solve 400 algorithms.

If I fail to solve three algorithms one time, then I will fail 300 algorithms; but I have tried 300 times to solve new challenges.


THINK AND GROW RICH SUMMARY (BY NAPOLEON HILL) - I want to watch 100 times

Oct. 20, 2019

Introduction


It is my personal finance research. I like to be a millionaire. How can I do it? I like to watch the video 100 times first. I like to get ideas how to grow rich.

100 times


Here is the link.


weekly contest 159 top 10 players - code study

Oct. 20, 2019

Introduction


It is hard to motivate myself to write more code. One of ideas is to motivate myself, study code from top 10 players, and then I can write different ideas from those players.

Top 10 players


I have to spend time to read their code. To be a better programmer, I have to learn to read hours of code, and I have to search for ideas, and also train myself as a good thinker. How quickly I can understand code in different languages, different approach.

Let us see who they are.




2019 fashion - Walk in the rain

Oct. 20, 2019

Introduction


It is my favorite walk last Saturday. I took the walk from downtown and then walked along waterfront. It is best activity for me to learn more about downtown, and also get some exercise.

2019 fashion - walk in the rain


Here is the list of things I took with me for a walk:

1. A cellular phone, battery
2. Half of baked potato, apple, orange, a bottle of water
3. A hat, gloves, umbrella, a scarf

I like to work on my fitness training. The weather is kind of cold, and I did walk for 2k - 3k distance.



When you have a friend solved 900 algorithms

Oct. 20, 2019

Introduction


It is a small world, I had chance to meet engineers as an interviewer on interviewing.io, so I do not need to pay coach fee, I can work with best engineer in the world after mock interview. I worked with one two months ago, but I learn difference between us, he solves problems much more efficiently.

Two months later


I shared one of solutions on leetcode.com after I played weekly contest, and then I got comment around 10:00 PM. Here is the post.

I had chance to learn to write a better solution, since I found that he also posted an answer, I wrote C# code using same idea as well.

When you have a friend


I always work hard to push myself to meet top talent people. Sometimes I can not tell how good people are as an engineer, senior engineer, Ph.D. graduate, Microsoft engineer, Facebook engineer. I just learn from them by  working on mock interview as interviewer/ interviewee, and exchange ideas through Leetcode discuss.

Here is the post.

C# Code study: a solution can be written in two loops

I chose to study top voted solution which is converted to a different problem. I like to describe this way, it is to find all sliding windows containing above average number of chars in "QWER". The dictionary to store is whole string except current sliding window. Why? It is so simple to write to the code and it can be solved in less than 15 minutes. The solution link is here.
Here are shortcuts I learn from your code:
  1. Define map using int as key, each char of "QWER" is the key which is ascii value; Avoid string IndexOf etc.
  2. Work on sliding window, start and end, for each end position from 0 to length - 1, run a loop on start as long as the balance string is met.
  3. Work on simplicity in design process and coding process. Right now there are less than 5 things to consider, map, ascii value, slide window, left, right, while loop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sliding_windows___study_code
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = BalancedString("QWER");
        }

        /// <summary>
        /// Oct. 19, 2019
        /// Leetcode 
        /// study code
        /// https://leetcode.com/problems/replace-the-substring-for-balanced-string/discuss/408978/JavaC%2B%2BPython-Sliding-Window
        /// It is to find all sliding windows containing above average number of chars in "QWER". 
        /// The dictionary to store is whole string except current sliding window. Why? It is so simple 
        /// to write to the code and it can be solved in less than 15 minutes.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int BalancedString(string s)
        {
            var exclusiveSlidingWindow = new Dictionary<int, int>();
            var length = s.Length;
            var minLength = length; 

            for(int i = 0; i < length; i++)
            {
                int key = s[i];
                if(!exclusiveSlidingWindow.ContainsKey(key))
                {
                    exclusiveSlidingWindow.Add(key, 0);
                }

                exclusiveSlidingWindow[key]++; 
            }

            int left = 0; 
            int average = length/4; 

            // Find all sliding window containing each char of "QWER" above average
            for(int index = 0; index < length; index++)
            {
                exclusiveSlidingWindow[s[index]]--;

                while(left < length && 
                    (!exclusiveSlidingWindow.ContainsKey('Q') || exclusiveSlidingWindow['Q'] <= average) && 
                    (!exclusiveSlidingWindow.ContainsKey('W') || exclusiveSlidingWindow['W'] <=average)  && 
                    (!exclusiveSlidingWindow.ContainsKey('E') || exclusiveSlidingWindow['E'] <= average) && 
                    (!exclusiveSlidingWindow.ContainsKey('R') || exclusiveSlidingWindow['R'] <= average))
                {
                    minLength = Math.Min(minLength, index - left + 1); 
                    exclusiveSlidingWindow[s[left]] += 1; // not in the sliding window
                    left++; // caught by online judge
                }
            }

            return minLength == length? 0 : minLength; 
        }
    }
}
I checked C# code shared here, and I learn that I can break giant expression in my above code. There are two tips:
  1. Declare exclusiveSlidingWindow hashmap using Dictionary class, and then use constructor to initiate four keys with initiate value 0;
  2. While loop giant expression can be removed, four case of 'Q', 'W', 'E', 'R' can be replaced using one aggregate function Max.
I wrote comment on my own post on Oct. 20, 2019 10:53 AM. 
The C# code seen in my friend's post: Idea 1: var freq = new Dictionary<char, int>() {{'Q', 0},{'W', 0}, {'E', 0},{'R', 0}}; Idea 2: freq.Values.Max()
var freq = new Dictionary<char, int>() {{'Q', 0},{'W', 0}, {'E', 0},{'R', 0}};
        int n = s.Length, res = n, i = 0;
        foreach(var ch in s)
            freq[ch]++;
        
        for (int j = 0; j < n; j++) 
        {
            freq[s[j]]--;
            while (i < n && freq.Values.Max() <= n / 4) 
            {
                res = Math.Min(res, j - i + 1);
                freq[s[i++]]++;
            }
        }
        
        return res;



I have a Google water bottle - 2019 achievement

Oct. 20, 2019

Introduction


It is an idea to write hope, work hard, embrace finance challenge when a single person lives in her 53 years old. I am thinking about how to hold on my memory 14 years in Florida, with paid off condo and some 401 K and IRA, I like to have life in Canada as well. I almost have lived in Canada 10 years, how to continue to push myself to strive and make a good living?

An idea 


I went to Google GHC meeting Oct. 4, 2019, and I got a Google water bottle. I like to learn from Google. I am using Google blogger to write blogs every day, use google gmail and also google map.

I chose to save money not to purchase a GPS, instead I like to download Google offline map and continue to use my used Samsung S6 as my alternative GPS.

I like to serve a lot of people in Canada like Google people do. Let me take a few picture with my favorite Google water bottle.

I only save around $60,000 Canadian dollars last 10 years in Canada. I have a stable job, I should have invested and make more money on stock market last 10 year bull market.

One idea is to serve more people in SJTU wechat group in the city of Vancouver. I just got invited last week. I like to learn more people from my university.








Keep myself healthy and kind

Oct. 20, 2019

Introduction




Mock interview progress

Oct. 20, 2019

Introduction


It is hard for me to push myself to practice more algorithm in weekdays. I only solved less than 20 algorithm starting from August 20 to October 20. A friend I knew solved 902 algorithm, he also practiced a lot of mock interview. Two months ago when we met, he only solved around 800 algorithm.

Mock interview progress


I like to look into mock interview progress. How to read the graph?


1234. Replace the Substring for Balanced String - Top players

Oct. 20, 2019

Introduction

I am lack of strong motivation in weekdays, but I do learn from my Saturday 7:30 pm 90 minutes weekly contest very well. Starting from 7:30 PM, I had four hour activities including contest, review, writing and exchange ideas.

Case study

Here are some facts:
1. One hour to work on algorithm 1234, another 15 minutes after the contest to complete the code;
2. Learned one more solution;
3. Studied top player ranking No. 1.

From 7:30 PM to 11:30 PM, that is four hours learning.

I have difficulty to describe using my English. There are some structure issues:

One hour struggle on this medium level algorithm 1234, I spent another 15 minutes after the contest to complete the code, and then learned one more algorithm, studied top player ranking No. 1. From 7:30 PM to 11:30 PM, that is four hours learning.

Here is the post.

C# code study: Weekly contest 159 ranking No. 1 - binary search

It is interesting to learn a solution written by weekly contest 159 ranking No. 1. Since his solution was written in less than 4 minutes. I like to figure out how we can shorten the time and expedite the problem solving process.
image
I will add more understanding how to design and make the code easy and quick to write. I think that as a designer, I have to learn various ideas to solve the problems first, and then I can choose easy one to write in weekly contest.
public class Solution {
    public int BalancedString(string s) {
         const string CHARS = "QWER";
            int length = s.Length; 
            var prefixCounts = new int[4][];

            for(int i = 0; i < 4; i++)
            {
                prefixCounts[i] = new int[length + 1]; 

                for(int j = 0; j < length; j++ )
                {
                    prefixCounts[i][j + 1] = prefixCounts[i][j] + (s[j] == CHARS[i]? 1 : 0); 
                }
            }

            int low = 0;
            int high = length; 

            while(low < high)
            {
                int middle = low + (high - low)/ 2; 
                var seriesCheck = false;

                for(int i = 0; i + middle <= length; i++)
                {
                    var now = new int[4];
                    var averageCheck = true; 

                    for(int j = 0; j < 4; j++)
                    {
                        now[j] = prefixCounts[j][i] + (prefixCounts[j][length] - prefixCounts[j][i + middle]);

                        if(now[j] > length/ 4)
                        {
                            averageCheck = false; 
                        }
                    }

                    seriesCheck = seriesCheck || averageCheck;
                }     
           
                if(seriesCheck)
                {
                    high = middle; 
                }
                else
                {
                    low = middle + 1; 
                }
            }

            return low; 
    }
}


1234. Replace the Substring for Balanced String - after the contest

Here is the post I learned to write in C#.

C# Code study: a solution can be written in two loops

I studied the code written by top player Lee215. I had to write my own C# code, and then asked myself questions, how do I understand to track sliding window count?

I chose to study top voted solution which is converted to a different problem. I like to describe this way, it is to find all sliding windows containing above average number of chars in "QWER". The dictionary to store is whole string except current sliding window. Why? It is so simple to write to the code and it can be solved in less than 15 minutes. The solution link is here.
Here are shortcuts I learn from your code:
  1. Define map using int as key, each char of "QWER" is the key which is ascii value; Avoid string IndexOf etc.
  2. Work on sliding window, start and end, for each end position from 0 to length - 1, run a loop on start as long as the balance string is met.
  3. Work on simplicity in design process and coding process. Right now there are less than 5 things to consider, map, ascii value, slide window, left, right, while loop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sliding_windows___study_code
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = BalancedString("QWER");
        }

        /// <summary>
        /// Oct. 19, 2019
        /// Leetcode 
        /// study code
        /// https://leetcode.com/problems/replace-the-substring-for-balanced-string/discuss/408978/JavaC%2B%2BPython-Sliding-Window
        /// It is to find all sliding windows containing above average number of chars in "QWER". 
        /// The dictionary to store is whole string except current sliding window. Why? It is so simple 
        /// to write to the code and it can be solved in less than 15 minutes.
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int BalancedString(string s)
        {
            var exclusiveSlidingWindow = new Dictionary<int, int>();
            var length = s.Length;
            var minLength = length; 

            for(int i = 0; i < length; i++)
            {
                int key = s[i];
                if(!exclusiveSlidingWindow.ContainsKey(key))
                {
                    exclusiveSlidingWindow.Add(key, 0);
                }

                exclusiveSlidingWindow[key]++; 
            }

            int left = 0; 
            int average = length/4; 

            // Find all sliding window containing each char of "QWER" above average
            for(int index = 0; index < length; index++)
            {
                exclusiveSlidingWindow[s[index]]--;

                while(left < length && 
                    (!exclusiveSlidingWindow.ContainsKey('Q') || exclusiveSlidingWindow['Q'] <= average) && 
                    (!exclusiveSlidingWindow.ContainsKey('W') || exclusiveSlidingWindow['W'] <=average)  && 
                    (!exclusiveSlidingWindow.ContainsKey('E') || exclusiveSlidingWindow['E'] <= average) && 
                    (!exclusiveSlidingWindow.ContainsKey('R') || exclusiveSlidingWindow['R'] <= average))
                {
                    minLength = Math.Min(minLength, index - left + 1); 
                    exclusiveSlidingWindow[s[left]] += 1; // not in the sliding window
                    left++; // caught by online judge
                }
            }

            return minLength == length? 0 : minLength; 
        }
    }
}