Friday, July 14, 2023

Leetcode: 4 sum

Here is the article. 

C# | Fail fast | What to learn? | Stay humble | July 14, 2023
774
5
3 hours ago
C#

Intuition

The idea is to work on a better solution than brute force, O(N^4). Sorting first, since it only takes O(nlogn) time. Next is to work on O(N^2) time complexity to construct two loops for third number and fourth number, meanwhile a hashmap is built to store all possible two sum with index position of the array.

Approach

I worked on 3+ submissions, and failed two times and then succeeded last time. One is TLE with an array with length 200, all with value 2, target is 8.

Next is "Wrong Submission", for integer 10^9, four of them as input array.

My solution is to add the following code to skip duplicate quadruplet.

 // pruning - avoid TLE
if(fourth > (third + 2 ) && numbers[fourth] == numbers[fourth - 2])
{
   continue; 
}

And declare hashmap using long instead of int in the following:

  // record first two number possible sum's hashmap 
  var map = new Dictionary<long, IList<int[]>>();

And declare long data type instead of int for variable sum:

long sum = thirdValue + fourthValue;

Complexity

  • Time complexity:

Time complexity:
Three loops

 for (int third = 0; third < length - 1; third++)
 ...
    for (int fourth = third + 1; fourth < length; fourth++)
    ...
        foreach (var item in map[search])

O(N^2) * O(M), M is hashmap size - upper bound is O(N^2)

In order to reduce hashmap size, it is important to remove duplicate entry in hashmap, so that the size can be lowered for extreme case: aray size 200, all with value 2, target 8. M can be lowered from above 10,000+ to 1.

  • Space complexity:

Space complexity:
O(N^2)

Code

/// <summary>
        /// Code review 
        /// July 14, 2023
        /// Time complexity: O(N^2), N is the length of array numbers
        /// Space complexity: O(N^2)
        /// </summary>
        /// <param name="numbers"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public IList<IList<int>> FourSum(int[] numbers, int target)
        {
            var quadruplets = new List<IList<int>>();

            if (numbers == null || numbers.Length == 0)
            {
                return quadruplets;
            }
            
            Array.Sort(numbers);

            // record first two number possible sum's hashmap 
            var map = new Dictionary<long, IList<int[]>>();
            var set = new HashSet<string>(); 

            // quadruplets unique - key using ,
            var keys = new HashSet<string>();

            var length = numbers.Length;

            // Work on last two numbers - third and fourth, time complexity:O(N^2)
            // all unique values - remove duplicate 
            for (int third = 0; third < length - 1; third++)
            {
                var thirdValue = numbers[third];

                for (int fourth = third + 1; fourth < length; fourth++)
                {   // pruning - avoid TLE
                    if(fourth > (third + 2 ) && numbers[fourth] == numbers[fourth - 2])
                    {
                        continue; 
                    }

                    var fourthValue = numbers[fourth];
                    long sum = thirdValue + fourthValue;

                    var search = target - sum;

                    if (!map.ContainsKey(search))
                    {
                        continue;
                    }

                    foreach (var item in map[search])
                    {
                        var first = numbers[item[0]];
                        var second = numbers[item[1]];

                        var quadruplet = new int[] { first, second, thirdValue, fourthValue };
                        var key = string.Join(",", quadruplet);

                        if (!keys.Contains(key))
                        {
                            keys.Add(key);
                            quadruplets.Add(new List<int>(quadruplet));
                        }
                    }
                }

                // It is time to add visited element into two sum dictionary.
                // Argue that no need to add any two indexes smaller than third, why? 
                // Just prove that it covers all possible numbers - easy to prove it!                
                for (int firstId = 0; firstId < third; firstId++)
                {
                    var firstNumber = numbers[firstId];
                    var firstTwoSum = firstNumber + thirdValue;

                    var newItems = new int[] { firstId, third };
                    var newKey = numbers[firstId] + "," + numbers[third];

                    // prune - reduce the size of value - List<int> length
                    if (!map.ContainsKey(firstTwoSum))
                    {
                        var items = new List<int[]>();

                        map.Add(firstTwoSum, items);
                    }

                    if (!set.Contains(newKey))
                    {
                        map[firstTwoSum].Add(newItems);
                        set.Add(newKey);
                    }
                }
            }

            return quadruplets;
        }

Citi CEO Jane Fraser: Organic growth strategy will take some time

 Here is the link. 

Citigroup CEO Jane Fraser sits down with CNBC's David Faber to discuss the company's investor day, growth strategy and more. For access to live and exclusive video from CNBC subscribe to CNBC PRO: https://cnb.cx/2NGeIvi 

Jane Fraser

 Jane Fraser (born 1967)[1] is a British-American banking executive who is the chief executive officer (CEO) of Citigroup, a position she has held since March 2021. Educated at Girton College, Cambridge, and Harvard Business School, she worked at McKinsey & Company for 10 years, rising to partner prior to joining Citigroup in 2004. In 2019, she was named president of Citigroup and CEO of its consumer banking division.[2]

In September 2020, Citigroup announced that she would replace Michael Corbat as CEO of Citigroup Inc. in February 2021, becoming the first woman to head a major U.S. bank.[3][4] She was included on Fortune's "Most Powerful Women in Business" list in 2014 and 2015 and has been called the "Number 1 Woman to Watch" for two consecutive years by American Banker.

John C. Dugan

 John C. Dugan (born June 3, 1955) is an American attorney who served as the 29th comptroller of the currency from August 2005 to August 14, 2010.[1] He has since worked as the chairman of Citigroup.

Early life and education[edit]

Dugan was born in Washington, D.C. He earned a Bachelor of Arts degree from the University of Michigan and a Juris Doctor from Harvard Law School.

Thursday, July 13, 2023

Virginial tech foundation | Endowment

 

Financial Highlights

Between July 1, 2020, and June 30, 2021, the value of the foundation’s assets grew reaching a total of over $2.6 billion. Expenditures in support of university projects and programs were $155.8 million, an decrease of 13.8 percent compared to the previous fiscal year. Foundation net revenues were $465.3 million. The value of the endowment was $1.69 billion at fiscal year's end.

Highway 1 - Kamloops to Alberta - Four Laning

Cliffhanger: $451M Upgrade for Treacherous Stretch of Highway 1 in British Columbia

The Kicking Horse Canyon

 The Kicking Horse Canyon, located just east of Golden, BC, is one of the most rugged and scenic sections to be found on the Trans-Canada Highway. As a tourist and commercial transportation corridor, the highway carries more than 10,000 vehicles daily during the summer. While the mix varies by season, up to 30% of the traffic consists of commercial vehicles moving millions of dollars in goods to serve interprovincial and international trade. Three phases of work have transformed 21 kilometres of narrow, winding two-lane highway into a modern four-lane, 100 km/h standard. Construction of the fourth and final phase to complete the remaining – and most difficult – 4.8 kilometres is expected to be substantially complete in winter 2023-24. This project is part of the comprehensive Highway 1 – Kamloops to Alberta – Four Laning Program. The challenge of this work is substantial and will involve significant traffic disruptions ranging from 20-minute stoppages to overnight closures and even multi-day closures during off-peak shoulder season.

Wednesday, July 12, 2023

林文胜 副教授

 1997-2000 上海交通大学 制冷及低温工程 工学博士

1988-1991 重庆建筑工程学院 供热、供燃气、通风及空调工程 工学硕士
1984-1988 上海交通大学 制冷设备与低温技术 工学学士

1991-1997 冶金工业部重庆钢铁设计研究院 助理工程师、工程师
2001-现在 上海交通大学机械与动力工程学院制冷与低温工程研究所 讲师、副教授
2008-现在 上海交通大学机械与动力工程学院制冷与低温工程研究所 副所长

一、现承担课程
[1] 低温原理及应用,本科生,48学时,3学分
[2] 二氧化碳捕集概论,本科生,48学时,3学分
[3] 制冷低温系统的设计与实践,研究生,48学时,3学分
[4] 系统工程,研究生,32学时,2学分
二、曾开设课程
[1] 建筑环境学,本科生,45学时,2.5学分
[2] 燃气供应,本科生,36学时,2学分
[3] 低温技术及其应用,本科生,36学时,2学分
[4] 低温热力学与传热,研究生,36学时,2学分
[5] 燃气新技术,研究生,36学时,2学分

刘永文 副教授

1997-2002上海交通大学动力工程及工程热物理专业博士 

2012至今 上海交通大学机械与动力学院 副教授

2011-2012 美国宾夕法尼亚州立大学 访问学者
2002-2010 上海交通大学机械与动力学院 副教授
1997-2002 上海交通大学机械与动力学院 讲师
1995-1997 上海交通大学动力机械系 讲师
1988-1991 上海一0一厂 工程师

1997-2002上海交通大学动力工程及工程热物理专业博士
1991-1994上海交通大学轮机工程硕士
1984-1988上海交通大学制冷及低温工程学士


燃气轮机等热力系统的建模、仿真和控制
多相流动的介观仿真

2021-2022,企业合作,“燃气轮机仿真模型开发及优化调试”,项目负责人
2020-2021,中国航发控制系统研究所,“重型燃机发电机组实时数学建模等技术研究”,项目负责人
2019-2022,国家两机重大专项项目,“燃气轮机总压畸变试验”,项目负责人
2017-2019,xx研究院 “xxxx改进方案的仿真与试验分析”,项目负责人
2016-2018,xx研究院 “xx燃气轮机热力参数在线自适应评估模型研究”,项目负责人
2016-2017,xx中国有限公司 “分布式能源标准化解决方案应用开发”,项目负责人
2014-2016,基础研究专项 “xx装置仿真基础技术及实验研究”, 项目负责人
2014-2014,华东电力试验研究所有限公司 “华能石洞口第三发电厂F级燃机调速系统建模”,项目负责人
2011-2012,教育部专项基金“基于模型的船用燃气轮机故障诊断”,项目负责人
2010-2011,上海汽轮机有限公司“给水泵小机电超速保护代替机械超速保护””,项目负责人
2009-2011,国家863计划项目“中低热值燃料R0110燃气轮机及其联合循环的性能建模和分析”,项目主持
2008-2010,中国航空动力控制研究所“燃机数学模型”,项目负责人
2009-2010,上海市科委“低热值煤气规模化利用和系统运行优化的研究”,主要参加者

重要的投资法则 | 笑傲股市


第13章 投资者常犯的21个错误

  1. 当损失很小并处于合理的范围时, 持股不动。 在人类情感的作用下, 大部分投资者本能上偏好小赔出局。 由于不想承受损失,便空怀希望继续等待,直到亏损变得非常严重,步得不付出昂贵的代价。这是目前为止,几乎所有投资者都曾犯过的最严重的错误之一;他们不明白,所有的普通股都是极具投机性的,并能带来巨大的风险。你必须尽量减少每一个损失,无一例外。在过去45年中,我在全国各地的课堂上都会教学生这样一个准则:当股价低于买入价7%或8%时,立即进行止损。遵循这一简单的原则,你可以在股市汹涌的浪潮中生存下来,并能把握住未来很多的良机。 
  2. 在股价下跌时买进,却越陷越深
  3. 买入时,向下摊平成本而非向上加码。
  4. 不学习如何使用线图,而且不敢买入那些即将在合理的价格形态上创下价格新高的股票。 
  5. 由于不懂得选股标准,也不知道应该具体关注成功企业的哪些方面,所以永远都无法在投资领域中入门。 比如, 选择劣质科技股。
当股价低于买入价7%或8%时,立即进行止损。

Page 819
第20章 重要的投资法则
  1. 不要买入廉价的股票

Algorithms you need to know before you take that Systems Design Interview

Here is the article. 

  1. Geohash | Location based service
  2. Quadtree | Location based service
  3. Consistent hashing | Balance the load within a cluster of services
  4. Leaky bucket | Rate limiter
  5. Token bucket | Rate limiter
  6. Trie | Search autocomplete
  7. Rsync | File transfers
  8. Raft/Paxos | Consensus algorithms
  9. Bloomfilter | Eliminate costly lookups
  10. Merkle tree | Identify inconsistencies between nodes
  11.  HyperLogLog | Count unique values fast
  12. Count-min sketch | Estimate frequencies of items
  13. Hierarchical timing wheels | Job scheduler
  14. Operational transformation | Collaborative editing

Tuesday, July 11, 2023

Mark Lucovsky

 Mark Lucovsky is an American software developer who is now employed by Google after resigning his role as General Manager of Operating Systems at Facebook. Prior to this, he worked at Microsoft and VMware.[1] He is noted for being a part of the team that designed and built the Windows NT operating system, which, starting with Windows XP, became the basis of all current Windows releases.

Lucovsky earned his bachelor's degree in computer science in 1983 from California Polytechnic State University, San Luis Obispo.[2] He worked at Digital Equipment Corporation, where he came to the attention of Dave Cutler and Lou Perazzoli.[2] When Cutler and Perazzoli moved to Microsoft to work on their next generation operating system after the cancellation of the PRISM and MICA projects at Digital, they asked him to join them.[2]

美联储宣布第6次加息之后

 本月初美联储宣布第6次加息之后,美股大跌,紧接着就是科技公司多米诺骨牌式地大裁员。

 

除了Meta亚麻的上万裁人,Twitter的50%裁员,还有:

  • Lyft:裁员13%,700人

  • Stripe:裁员约1100人

  • Chime:裁员160人

 

早就加入裁员大潮的公司还有:

  • Netflix:裁员约450人

  • 微软:裁员1100人

  • Coinbase:裁员1100人

  • Shopify:裁员1000人

  • Snap:裁员超过1000人

  • Robinhood:裁员31%

  • 特斯拉:裁员10%


除了AWS和Ads等核心部门,其他亚麻的员工大概都在瑟瑟发抖。

 

平时有好日子过的时候,亚麻都会PIP绩效裁人。如今危机来了,只能说所有不赚钱的部门都危险。

 

此次裁员,对于新入职的同学来说也是个危险信号。即使当时拿着大包进来的,如今裁员当头,很有可能是被首先牺牲的对象。

科技业员工被裁人数

亚马逊、Google等大型科技公司,历经新冠疫情期间需求大增而快速增员之后,今年也都削减人力。根据MarketWatch报导,今年来全球科技业已有21.6万人丢掉饭碗,才上半年即已超过去年全年。 

根据求职网站Layoffs.fyi的资料,科技业员工被裁人数1月中旬以来开始爆增七倍多,到目前为止,全球已有824家科技公司裁员。去年则有1,024家科技公司裁员,缩减人力154,336人。


另外,纽约时报同日也宣布裁撤运动部门,往后赛事、球员及联盟动态将仰赖去年初以5.5亿美元收购的“运动员”(The Athletic)网站报导。不过纽时强调,并不会有人因此而失业。

Air Canada Pilot Salary

 How much money does an Air Canada pilot make? Well, that’s a very loaded question. So much so, that even my banker gets confused when I’m applying for a loan! The answer varies wildly depending on what airplane you fly, where you fly to, the number of years you’ve been at the company, how many hours you fly and last but certainly not least, the seat you’re qualified to fly in.

When comparing the baseline salaries amongst major airlines in Canada, Air Canada’s, on average, are amongst the highest in the country. Like most other flying jobs, a pilot’s salary is based upon a baseline hourly rate and the number of flying hours they work.

The hourly rate is based upon the type of aircraft you fly, whether you’re qualified as a Captain, First Officer, or Relief Pilot, and the years of service you have at Air Canada. A pilot’s monthly salary is then dependant upon how many hours they fly in that month. The company guarantees that a pilot will be paid a minimum of 75 hrs per month, but the exact number of hours worked can, and usually does, vary with each month and with the peak travel seasons.

Generally speaking, pilots have a lot of control over what airplane and position they choose to fly. If you happen to be financially oriented, you can choose to fly the biggest airplane and the highest paying position that your seniority can hold. But, this usually comes at the cost of less control of your schedule and quality of life.

If better control of your schedule and lifestyle are more important to you, then the Air Canada pilot salary will change as you choose to be more senior on a lower paying aircraft or position.

How much money do Air Canada pilots make?

Here are a few examples of the average pilot salaries for different positions at Air Canada based on 6 years of service and an average of 75 flying hours per month:

A220 FO $80,052
A220 CA $194,640

B737 FO $111,852
B737 CA $196,212

A320 FO $113,088
A320 CA $198,708

A330 FO $142,524
A330 CA $256,980

B787 FO $145,500
B787 CA $262,989

B777 FO $157,032
B777 CA $286,296

The Air Canada pilot salary is quite attractive and motivate a fair number of pilots to want to apply to fly for Air Canada. As such, the hiring process can be competitive and can takes years of expensive training generally followed by years of flying experience to build the qualifications and credentials necessary to be successfully hired by Air Canada. In fact, because it so competitive, it is not uncommon for pilots to migrate to Air Canada from other major Canadian airlines such as Wesjtet and Air Transat.

Unfortunately, for most new hire pilots at Air Canada, accepting one of these coveted positions usually means accepting a pilot job with some of the lowest starting salaries amongst the major airlines in Canada.

How is this so if Air Canada’s salaries are the highest in the Canadian Aviation Industry?

This is because the first 4 years of pilot pay are at a substantially lower and fixed pay rate which remains the same irrespective of what airplane a pilot is assigned to fly. What that means is that for the first few years of their career, the Air Canada pilot salary is the same regardless of whether they fly as a B777 FO or a A220 FO.

So, in the first year a new pilot at Air Canada can expect to make around $57,375 based on flying 75 flying hours per month. Generally speaking, for most pilots starting at Air Canada this first year salary is, more often than not, paradoxically an initial step down in pay for the first few years.

Depending on one’s own financial situation, this can sometimes be a very difficult burden to overcome for the first few years. In fact, some pilots decide to forgo the offer of employment at Air Canada because of this very reason.

Hopefully this give you a better idea of what kind of salary you can expect when working at Air Canada. The career path you choose at the airline is entirely dependant upon your goals and lifestyle choices. These choices ultimately affect your salary at the airline.

Are pilots well paid in Canada?

Generally speaking, no. In the long term, the Air Canada pilot salary is seen as the highest in Canada. However, if you compare their starting salary, it can be much lower than other airlines in Canada. Generally speaking, pilots in Canada are not paid well when compared to their American counterparts. In 2022, a regional airline in the US was hiring for direct entry Captains on a small regional jet for a salary of $158,000 USD per year, starting in year one, and with an additional signing bonus.

What is the highest salary of Pilot in Canada?

Pilots at Air Transat can easily make $250,000 CAD per year after many years of service as a Captain. Air Canada Captains with a lot of seniority who are motivated by income and who do overtime can push more than $400,000 CAD per year towards the end of their retirement.

Air Canada Pilot Salary Per Hour?

It is true that Air Canada pilots do receive an hourly rate. This minimum hourly rate is then added onto other hourly rates such as navigational pay, weight pay, overnight pay, and more. The true Air Canada pilot salary only exists for the first 4 years or until pilots move onto what is known as formula pay. Formula pay, which incorporates all of these additional pay types, is rather convoluted and tends to stump even the smartest of Air Canada pilots.