Wednesday, April 6, 2022

Leetcode | discuss | 30 days to Meta onsite | 4th Facebook onsite | System design | Daily update - Day 3

April 6, 2022

Here is the link. 


30 days to Meta onsite | 4th Facebook onsite | System design | Daily update - Day 3

April 4, 2022

Introduction

I like to quickly share my preparation for Meta 2022 phone screen and onsite. I like to document my learning on system design, also seek good advice and build confidence based on hard work, good learning strategies and also satisfaction through hard work, preparation, sharing and great social activities within community. Good learning and great success always come after those people hard working, taking risk, determination to make good plans, execution of plans. If you also prepare for system design interview, or algorithm interviews for Meta onsite, please drop a line in the comment area, or share your discuss post on Leetcode. If my notes can help you to practice more on Leetcode algorithms, then let me know as well.

30 days to Meta onsite | System design
I did purchase a few udemy system design and behavior courses, and started to watch those courses.

image

image

I will take some notes and then share in this discuss post if I have time.

I also had chance to watch mock onsite interview from https://www.designclub.mingdaoschool.com/interview/index.html

Books I read last 12 months to prepare system design

Google tech talks watched
Bigtable in action (Google Cloud Next '17) [Here](Bigtable in action (https://www.youtube.com/watch?v=KaRbKdMInuc&t=1965) is the link.
Field promotion - keyword, google search - NoSQL row BigTable key design - Cloud Bigtable & time series data Here is the article.

Google bigtable, GFS, MapReduce paper
My favorite notes from Harvard, Rutgers, etc. university large distributed system lecture notes:
August 5, 2021
I like to take some time to learn Harvard lecture notes about Bigtable. Here is the link.

The following is the lecture notes with my highlights. I also like to write down my study notes to help myself to be a better learner.

Follow up on August 5, 2021 7:15 PM
I just could not believe that it is best lecture note I read in my whole life. Unbelievable!

Bigtable makes a couple data model choices relevant for our understanding.

  • Sparse hashtable. A Bigtable is essentially a sparse 3D hash table, where the dimensions are row names, column names, and versions (timestamps).
  • Strings. All Bigtable row names, column names, and data items are strings (sequences of characters). Bigtable has no true schema: everything’s a string.
  • Put, get, scan. Bigtable supports four fundamental operations: put (store a value in a row/column entry), get (return the value in a row/column entry), delete (delete a row/column entry), and scan (return many values from many row/column entries, in sorted order).

Algorithms I practiced before and after Meta phone screen | C# | Facebook tag | votrubac
I just could not believe that I passed Meta phone screen this year March 21, 2022, so I am preparing for onsite interviews in May, 2022.

Facts to review:

  1. Interviewing dot io mock interview as an interviewees - four times in February, 2022.
  2. Algorithms solved - another over 40 algorithms solved for preparation, submissions count over 100
  3. Book chapter - written by Dr. Li - Follow the book chapter to review algorithms related to array
  4. Lessons learned from March Microsoft onsite interviews - C#, algorithms, bugs in the code, time complexity related to HashSet. Need more practice. Work hard and review more algorithms.
  5. It is more important to pass Meta onsite algorithm interviews compared to system design interview.

10 algorithms practiced most challenge:

    1. Step-By-Step Directions From a Binary Tree Node to Another
      C# | Post order | Study discuss post | Solve TLE problem
    1. Expression Add Operators (Hard level)
      C# | Excellent learning opportunity
      C# | Learning opportunities
    1. Reorder Routes to Make All Paths Lead to the City Zero
      C# | Graph problem | Quick study | Warmup
    1. Shortest Subarray with Sum at Least K
      C# | Design a deque | Review Array - Subarray | 2022 March

Jan. 17, 2022
I came back to work on algorithm since I had to prepare for Microsoft Vancouver online assessment.


257. Binary Tree Paths
C# | Warmup | Backtracking | StringBuilder | Jan 16, 2022

1647. Minimum Deletions to Make Character Frequencies Unique
C# | Copy the idea and warm up | Keep it simple using one hashset and one array | Jan 16 2022

151. Reverse Words in a String
C# | Warmup for onsite | Define start and end char in a word | 2022 Jan 19
C# | Define start and end index of a word | C# StringBuilder Insert API | Insert the word right away


210. Course Schedule II
C# | DFS algorithm | Study Leetcode discuss C# code | Jan. 26, 2022
C# | DFS solution | Java code -> C# code | Jan. 26, 2022

874. Walking Robot Simulation
C# | Warmup algorithm and short review | 2018 Oct. 14

692. Top K Frequent Words
C# | Warmup practice | Sort once | Using simple data structure

636. Exclusive Time of Functions
C# | Opportunistic learning | Study C# code
C# | Lessons learned | My failed practice 54/120 test cases in 2020

263. Ugly Number
C# | Practice in Sept. 14, 2018
Feb. 8, 2022

1405. Longest Happy String
C# | Failed test case 24/35 | Think more carefully in design
C# | Greedy on char with largest count only | Longest is not easy

545. Boundary of Binary Tree
C# | Definition of left boundary | Reasoning behind | Feb. 2022

827. Making A Large Island
C# | Map each island using integer | Hashmap | DFS | Failed a few times

424. Longest Repeating Character Replacement
C# | Sliding window technique | mock interview

98. Validate Binary Search Tree
C# | Mock interview practice | Interviewer with MSFT, Amazon, Oracle, Meta | 2022 Feb. 23

March 4, 2022
Microsoft Vancouver onsite - Four rounds of algorithm interviews
I passed online code assessment in Dec. 2021, but I preferred to have more practice before I had onsite interview. I chose not to move fast because I did not practice very often from May to Dec. 2021. That is a big mistake, I should not stop practice Leetcode algorithms. It takes time to warm up and also it takes time to build habit to think hard on Leetcode algorithms, and also patience is a skill to learn again after six months break.

I continued to practice Leetcode algorithms to prepare Meta phone screen on March 21, 2022..

March 2022, monthly review
March 1 - March 7
It takes self-discipline to work on Leetcode algorithms continuously. I only have less than 200 submissions last 12 months, compared to Dr. Lai (https://leetcode.com/justyy/), over 1500 submissions, I like to learn from him. Hard work is most important, and I should discipline myself and then I can improve my crafting skills and problem solving skills.
Algorithms I worked on, 408, 1650, 1762, 314, 498, 162, 523, 282
I started to work on algorithms from votrubac, top-voted solutions: Another 11 algorithms, 1162, 1553, 992, 934, 1249, 1092, 1062, 959, 983, 1544

March 6, 2022
408. Valid Word Abbreviation
C# | learn from failed test cases


1650. Lowest Common Ancestor of a Binary Tree III
C# | Space complexity O(1)

1762. Buildings With an Ocean View
C# | Using stack

314. Binary Tree Vertical Order Traversal
C# | Preorder traversal | Record total count, horizontal, level in the tree
March 7, 2022
498. Diagonal Traverse
C# | Automatically direction change

162. Find Peak Element
C# | Binary search algorithm

523. Continuous Subarray Sum
C# | Learn from failed test cases
March 5, 2022
Algorithm to plan to work on
I chose to work on Leetcode with tag Facebook, last six month most frequent algorithms.
Algorithm 314, 1762, 1570, 1650, 528, 408, 339, 71, 31, 670;
10 more: 498, 162, 523, 282, 1891, 1011, 708, 1382, 1539, 2060;
10 more: 266, 286, 1868, 1216, 348, 778, 536, 270, 1428, 825;
10 more: 269, 658, 16, 2056, 43, 1060, 380, 1344, 1522, 1944;
10 more: 1644, 2076, 689, 1424, 983, 224, 298, 742, 767, 333;
10 more: 2019, 2033, 238, 1541, 1209, 2071, 296, 1244, 2065, 2081;
10 more: 406, 271, 1498, 735, 163, 1245, 1559, 247, 2025, 1197;
723, 2092, 62, 540, 1985
work hard | Hard work beats talent
Do not think too much. Just work on more algorithms. Solve as many algorithms as I can. Once I solve another 20 algorithms, stop and review what I have learned, and then continue to solve another 20 algorithms.
I wrote a blog to document my plan on March 5, 2022. Good planning is important for success for any project.
I understood that I could not solve all those algorithms, I tried to go over some algorithms quickly, and found those most intersting and practice one or two, and I tried different ideas to learn from others from discuss post.

March 8, 2022
282. Expression Add Operators (Hard level)
C# | Excellent learning opportunity
C# | Learning opportunities
March 16, 2022
39. Combination Sum
C# | Warmup practice | DFS | Backtracking | 2022

128. Longest Consecutive Sequence
C# | Time complexity: O(N) | Python code converted to C#

C# | Time complexity: O(N), N is length of the array
Leetcode 78 subsets, 90 Subset II, 77 combinations, 40 Combinations Sum II, 377 Combination Sum IV
Plan to type those python code from Li Yin's book, and then convert those code into C# code.

March 17, 2022

15. 3Sum
C# | Time complexity: O(N^2) | Review code written in 2016
C# | Warmup in 2022 | Using HashSet to remove duplicate
C# | Time complexity O(N^2) | Remove duplicate by sorting, no use of HashSet
C# | Time complexity O(N^2) | Use HashSet

18. 4Sum
C# | Sorting, sliding window, skip duplicate | Time: O(N^3)

454. 4Sum II
C# | Optimal time complexity: O(N^2), not O(N^3)

March 21, 2022

2096. Step-By-Step Directions From a Binary Tree Node to Another

C# | Preorder | TLE error 287/332
The above practice shows that I have weakness in terms of design recursive function, use post order traversal or preorder, TLE issue.

C# | Post order | Study discuss post | Solve TLE problem

C# | Post order traversal | Solve TLE problem
I practice near 10 algorithms last weekend, and I chose to study discussion post written by votrubac top-voted discuss posts.
I found so many issues and learned how to solve a few more algorithms related to DP, tree and graph problems.
March 21, 2022

1162. As Far from Land as Possible
C# | BFS | All land nodes into Queue | Search together

1553. Minimum Number of Days to Eat N Oranges
C# | Understand the subproblems

992. Subarrays with K Different Integers
C# | At most K | Two subproblems -> difference

934. Shortest Bridge
C# | Apply DFS to visit all nodes in each island | Brute force two nodes' distance

1249. Minimum Remove to Make Valid Parentheses
C# | Using stack | * to replace unmatched parentheses


1092. Shortest Common Supersequence
C# | LCS DP solution first | Learn C# code

1062. Longest Repeating Substring
C# | DP solution | Time complexity: O(N^2)

959. Regions Cut By Slashes
C# | DFS | Understand the problem

983. Minimum Cost For Tickets
C# | DP solution | learn 20 algorithms from one player

1524. Number of Sub-arrays With Odd Sum
C# | New idea to find algorithm to work on | Solutions tag

March 22, 2022
1675. Minimize Deviation in Array
C# | Learn the analysis first | Learn C# code

March 21, 2022
Meta phone screen, one week break, no practice. I did some research what to work on related to system design interview, and I decided to purchase some Udemy courses so that I can learn much better about large distributed system. Based on my analysis of Udemy course, for example, 15000 students, each one pays $15 dollars, the capital is $225,000 for one course. I do think that one of those courses will definitely help me in short time period.

March 31, 2022
1466. Reorder Routes to Make All Paths Lead to the City Zero
C# | Graph problem | Quick study | Warmup

1320. Minimum Distance to Type a Word Using Two Fingers
C# | DP solution | Need more time

April 1, 2022
1371. Find the Longest Substring Containing Vowels in Even Counts
C# | "aeiou" -> one integer, 5 bits, 32 variations | Warmup for Meta onsite

1721. Swapping Nodes in a Linked List
C# | One pass | Kth node and kth to Last | Secret - one follower starts kth node

Day 1
I was so excited since I learned how to take care of my own study, and also happy to share my own experience. I felt much better this time to prepare for system design, I love to spend time to follow lectures on udemy courses related to large distributed system.

Day 2
April 5, 2022
Spend most time to watch the video - course:
Udemy course: Software architecture & technology of large-scale systems
Spend time to watch videos:
Section 7

Module contents overview
Reference system for using tech platforms
Web applications
Solutions for web applications
Apache web server
Apache web server architecture
Apache webserver scalability
Nginx webserver
Nginx architecture
Nginx as reverse proxy and cache
Web containers & spring framework
Jetty & Spring
Node.JS
Node.JS event loop
Cloud solutions for web
Cloud storage
Cloud CDN
Services
Services solutions
Memcached
Memcached architecture
Redis cache & its architecture
Cloud caching solutions
RabbitMQ
RabbitMA architecture
Kafaka architecture
Redis Pub/Sub
Cloud MQ solutions
Datastores
Datastore solutions
RDBMS scalability architecture
NoSQL objectives & trade-offs
Amazon DynamoDB
DynamoDB architecture
Google BigTable
BigTable architecture
HBase
Cassandra
Cassandra features
MongoDB
MongoDB architecture
Analytics
Analytics solutions
Logstash data streaming architecture
Fluented
Elasticsearch
Elasticsearch architecture
Hadoop HDFS
Map-Reduce
Apache Spark
Stream processing
Summary
Technology stack presentation slides

I only had time to watch around one hour on Google BigTable and Bigtable architecture, and I plan to watch a few more.

Algorithm practice: None
Need to figure out how to spend one hour at least to work on algorithms, go over algorithms by taking some breaks, like 15 minutes, 30 minutes one time. Three times a day.

Day 3
It is an exciting day to work on Leetcode algorithm. First, I got this recipe from votrubac solution top-voted. 15 algorithms, I wrote a blog on April 1, 2022, and I made some plans to work on.

image

My plan | From my blog | April1, 2022 | Leetcode algorithm practice: votrubac | Top voted algorithms | Another 15 algorithms
Quickly go over 15 algorithms, think about five minutes for each algorithm;
Sort algorithms by priority, work on high priority ones first;
Work on challenging ones first.
Think about how to reward myself for the hard work
Time start: April 1, 2022 6:43 PM

I did code two algorithms, first one I was not lucky and I coded a brute force solution, and I learned from two comparison solution from votrubac.
1547. Minimum Cost to Cut a Stick
C# | Hard level | DFS + Memo | Opportunistic algorithm review for Meta onsite

Next I worked on a hard level algorithm, and I studied C# solution and wrote my own solution.

Next I followed advice from votrubac, reviewd a few algorithms, 312, 1000, 1039. I came cross my discuss post written in 2019 with 6 up-votes, I just could not believe that I did such great job to write something for this hard level algorithm in 2019. I was three year younger, and passion about algorithms, specially on DP solutions.

  1. Minimum Cost to Merge Stones
    C# dynamic programming solution bottom up - how to hack one?

I just could not believe that I could have same amount time to work on the hard level algorithm again this time. I quickly reviewed and skipped to next algorithm.

  1. Ways to Split Array Into Three Subarrays
    C# | Linear solution | First divide position any, second one is in a range

Day 4
Day 5
Day 6
Day 7
Day 8
Day 9
Day 10
Day 11
Day 12
Day 13
Day 14
Day 15
Day 16
Day 17
Day 18
Day 20
Day 21
Day 22
Day 23
Day 24
Day 25
Day 26
Day 27
Day 28

#MetaOnsite #onsite #Facebook #SystemDesign

system designonsitealgorithm interview30 days preparationspeculationvotrubactop voted votrubac15 algorithms votrubacjianminchenfacebook

Leetcode profile:

April 6, 2022 

https://leetcode.com/frankkkkk/

1712. Ways to Split Array Into Three Subarrays

[Java/Scala] Detailed Explanation - Prefix Sum - Binary Search

Here is the link.

I like to go over the profile top-voted discussion:



Monday, April 4, 2022

Some of the first quarter's biggest losers could be the biggest steals, Jim Cramer says

April 4 2022

Here is the link.

S&P 500 IN 1Q 2022

Biggest winners

  1. Occindental petroleum  96% gain
  2. The mosaic co 69%
  3. Halliburton co. 66%
  4. APA corp 54%
  5. Marathon oil corp 53%
Biggest losers
  1. EPAM systems loss 56%
  2. ETSY 43%
  3. Paypal holdings 39%
  4. Netflix inc 38%
  5. IPG Photonics corp 36%
DOW IN 1Q 2022

Biggest winners
  1. Chevron corp            39%
  2. The travelers cos.     17%
  3. American express    14%
  4. Dow inc.                  12%
  5. Caterpillar inc            8%
Biggest losers
  1. The home depot               28%
  2. Nike inc                           19%
  3. Salesforce inc                  16%    
  4. 3M CO.                            16%
  5. Walgreens boots alliance  14%

Sunday, April 3, 2022

Udemy course: Software architecture & technology of large-scale systems

April 3, 2022

Introduction

It is the best course for me to prepare Meta onsite interview in a month. I like to learn so many things in terms of system design, large distributed system. This is the first time I took Udemy approach, and I just could not believe that I made such great choice. 

Section 7 

  1. Module contents overview
  2. Reference system for using tech platforms
  3. Web applications
  4. Solutions for web applications
  5. Apache web server
  6. Apache web server architecture
  7. Apache webserver scalability
  8. Nginx webserver
  9. Nginx architecture
  10. Nginx as reverse proxy and cache
  11. Web containers & spring framework
  12. Jetty & Spring 
  13. Node.JS
  14. Node.JS event loop
  15. Cloud solutions for web
  16. Cloud storage
  17. Cloud CDN
  18. Services
  19. Services solutions
  20. Memcached
  21. Memcached architecture
  22. Redis cache & its architecture
  23. Cloud caching solutions
  24. RabbitMQ
  25. RabbitMA architecture
  26. Kafaka architecture
  27. Redis Pub/Sub
  28. Cloud MQ solutions
  29. Datastores
  30. Datastore solutions
  31. RDBMS scalability architecture
  32. NoSQL objectives & trade-offs
  33. Amazon DynamoDB
  34. DynamoDB architecture
  35. Google BigTable
  36. BigTable architecture
  37. HBase
  38. Cassandra
  39. Cassandra features
  40. MongoDB
  41. MongoDB architecture
  42. Analytics
  43. Analytics solutions
  44. Logstash data streaming architecture
  45. Fluented
  46. Elasticsearch
  47. Elasticsearch architecture
  48. Hadoop HDFS
  49. Map-Reduce
  50. Apache Spark
  51. Stream processing
  52. Summary 
  53. Technology stack presentation slides

How Landlords Can Check a Tenant's Credit Report

April 3, 2022

Here is the report. 


Saturday, April 2, 2022

Tesla is going to go 'significantly lower': GLJ Research CEO Gordon Johnson

April 2, 2022

Here is the link. 

Gene Munster, founder and managing partner at Loup Ventures, and Gordon Johnson, founder and CEO of GLJ Research, join CNBC's 'Squawk Box' to break down shares of electric-vehicle maker Tesla. For access to live and exclusive video from CNBC subscribe to CNBC PRO: https://cnb.cx/2NGeIvi 


Leetcode discuss: 1371. Find the Longest Substring Containing Vowels in Even Counts

April 2, 2022

Here is the link.

C# | "aeiou" -> one integer, 5 bits, 32 variations | Warmup for Meta onsite

April 1, 2022
Introduction
I could not come out working ideas to solve the algorithm. I tried to solve it using sliding window to beat brute force O(N^2) solution, but it does not work. I was so nervous since I could not find a solution, there are five vowel chars, and I need to determine left pointer with matching vowel char count even or odd. Left pointer can be moved forward and backwrad two directions. So I chose to read votrubac solution, since I chose to go through algorithms based on his up-voted algorithms.

Idea to count all vowel chars "aeiou" | even 0, odd 1| "0001" meaning: a is odd, four chars in "eiou" even | Easy to play
Go through each char in given string once, and record the count in terms of 0 or 1 for five chars in "aeiou". If it is not found then set variable smallestIndex, apply substring comparison to any char not just vowel char. Do not skip non-vowel in comparison. Try yourself first, and then read my C# code, good luck!

Bit operation | C# | My bug written in my first practice
It is easy for me to write a C# bit operation algorithm. I checked all C# discuss post, none of them uses bit operation, so I decided to write one. But my code failed to return correct answer, given example, eleetminicoworoep, should return 13, but mine is 12. I could not figure out the reason, so I had to spend over 10 minutes to debug.

I should apply caclulation of matching vowel chars "vowel" even substring to any char, not just vowel. In other words, "leetminicowor", my search stops "leetminicowo", but skip last char 'r' since it is not vowel.

I quickly fixed the bug to limit scope of if statement in the following:

// update bitVariation if it is vowel char
if (index >= 0)  // if it is vowel char
{
    var current = 1 << index;  // left shift
    bitVariation ^= current; // double check XOR ^
}

Do you think that it is worth time for me to practice writing and debugging? I have ideas to solve the problem using bit operation, and I can write C# code but I stumbled a few places since I did not practice and took breaks over six months in 2021.

Places I stumbled in C#:

  1. Declare C# bool[32] variable found, default value is false; but I was not sure until I debugged the code;
  2. C# String.IndexOf(char) - syntax and usage, I have to depend on Visual Studio prompt to determine;
  3. C# << left shift, only provide information once, vowels = "aeiou", I can quickly figure out how many bits to shift left;
  4. C# XOR ^ - this is important XOR using module 2 as result, in other words 1^1 = 0, 1^0 = 1, 0^0 = 0;

The algorithm I chose to work on based on votrubac
I cannot find time to work on more than 200 submission last 12 months, so I have to figure out ways to compensate on this lack-of-hardwork. After carefully reviewing my options, I choose to work on a most reputable player and his up-voted algorithms, compared to mock interview, paid udemy FANG interview algorithm courses. Here is the idea. Welcome comments how to choose algorithms to work on to prepare Meta onsite. I have this idea after I reviewed 50 algorithms tag Facebook last six months.

image
image

The current algorithm is fourth algorithm below red circled algorthm in page 2.

The following C# code passes online judge.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1371_Find_longest_substring
{
    class Program
    {
        static void Main(string[] args)
        {
            var longest = FindTheLongestSubstring("eleetminicoworoep");
            Debug.Assert(longest == 13);
        }

        /// <summary>
        /// code review on April 1, 2022
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static int FindTheLongestSubstring(string s)
        {
            if (s == null || s.Length == 0)
                return 0; 

            var vowels = "aeiou";
            var smallestIndex = new int[32];
            var found = new bool[32]; // default - false           

            smallestIndex[0] = -1;
            found[0] = true;

            var bitVariation = 0; // five bit, each bit matches one of vowel char "aeiou"
            var length = s.Length;
            var maxSubstringLength = 0; 

            for (int i = 0; i < length; i++)
            {
                var c = s[i];
                var index = vowels.IndexOf(c);

                // update bitVariation if it is vowel char
                if (index >= 0)  // if it is vowel char
                {
                    var current = 1 << index;  // left shift
                    bitVariation ^= current; // double check XOR ^
                }

                // it applies to any char
                if (!found[bitVariation])
                {
                    smallestIndex[bitVariation] = i;
                    found[bitVariation] = true;
                }
                else
                {
                    maxSubstringLength = Math.Max(maxSubstringLength, i - smallestIndex[bitVariation]); 
                }                
            }

            return maxSubstringLength; 
        }
    }
}

Friday, April 1, 2022

AT&T CEO John Stankey breaks down WarnerMedia-Discovery merger and dividend cut

March 4, 2022

Here is the link.

AT&T CEO John Stankey sits down with CNBC 'Squawk Box' team in Pebble Beach, California, to explain why the company decided to spin off WarnerMedia with Discovery in a $43 billion transaction. For access to live and exclusive video from CNBC subscribe to CNBC PRO: https://cnb.cx/2NGeIvi 

Leetcode algorithm practice: votrubac | Top voted algorithms | Another 15 algorithms

 April 1, 2022

Introduction

It is art to balance the effort to practice Leetcode algorithms. What to choose from? How fast should I review algorithms? Focus on ideas, coding, production-ready code or any other concerns? I do not know too much. I like to work on another 15 algorithms. 

votrubac | Top player | Top-voted algorithms



My plan 

  1. Quickly go over 15 algorithms, think about five minutes for each algorithm;
  2. Sort algorithms by priority, work on high priority ones first;
  3. Work on challenging ones first. 
  4. Think about how to reward myself for the hard work
  5. Time start: April 1, 2022 6:43 PM