Tuesday, July 4, 2023

Leetcode | 2022 practice

 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 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

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

It is much better to work on algorithms for a few hours, so that I could go over at least 10 algorithms and learn so many things during my study and practice. I started to code for an easy algorithm first, and then go back to write again using a simple solution, and learn lesson for my reading skills, and then I have chance to work on hard level algorithms, and review related algorithms. This experience definitely is best I can do to prepare.
Total hours: 4+ hours algorithm practice

April 12, 2022
I worked on a hard level algorithm, 1542. Find Longest Awesome Substring, my two practices:

  1. Failed practice, C# | First position | Bit manipulation | Failed: "9498331" | Lessons learned;
  2. Study code, C# | Last position | Bit manipulation | Study code

36. Valid sudoku
C# | Encode 1-9 digits to each row and each column and 9 3 x 3 matrix
C# | Encode string - three ideas to map same row, same column, same 3 x 3 matrix
C# | Validation process | HashSet


295. Find Median from Data Stream (Hard level)
I chose to write a different solution to make my life easy. I like to have simple function, easy to follow. So, I wrote down my approch, and then wrote C# code and played with the idea.
C# | Minimum heap and maximum heap | SortedSet<Tuple<int, int>>

  1. Game of Life
    C# | in-place algorithm using module 10

Day 29

  1. Find K Pairs with Smallest Sums
    C# | Minimum heap | SortedSet<Tuple<int, int, int> | Two neighbors: right and bottom

May 19, 2022
1632. Rank Transform of a Matrix
C# | Quick learner | Union find algorithm | Illustration using diagrams

  1. Maximum Number of Consecutive Values You Can Make
    C# | Quick learner | I tried 10 minutes to figure out something first

May 17, 2022
1855. Maximum Distance Between a Pair of Values
C# | Two sorted arrays | Two pointer technique | Linear time complexity

  1. Largest Multiple of Three
    C# | Quick learner | At most remove two digits

  2. Maximum Sum of Two Non-Overlapping Subarrays
    C# | Quick learner | 30 minutes to study

May 12, 2022
907. Sum of Subarray Minimums
C# | Quick learner | Using stack O(N) time complexity | Play for fun

  1. The k Strongest Values in an Array
    C# | Quick learner | two pointers

May 5, 2022
1915. Number of Wonderful Substrings
C# | Quick learner | 10 bits to represent a - j count as odd or even

  1. Min Cost to Connect All Points
    C# | Quick learner | Union find algorithm

May 4, 2022
2062. Count Vowel Substrings of a String
C# | Quick learner | Sliding window

May 3, 2022
984. String Without AAA or BBB
C# | Quick learner | greedy idea

  1. Queue Reconstruction by Height
    C# | Quick learner from an example

May 2, 2022
255. Verify Preorder Sequence in Binary Search Tree
C# | 15 minutes as a quick learner | Recursive solution

  1. Number of Digit One
    C# | 30 minutes to work on hard level

  2. Find K Pairs with Smallest Sums
    C# | Minimum heap | SortedSet<Tuple<int, int, int> | Two neighbors: right and bottom

  3. Game of Life
    C# | in-place algorithm using module 10

  4. Number of Matching Subsequences
    C# | Group words by starting char | Avoid TLE error

  5. Binary Watch
    C# | Bit manipulation | DFS algorithm

April 26, 2022
458. Poor Pigs
C# | Hard level | One pig can test multiple buckets a time

April 25, 2022
234. Palindrome Linked List
C# | Optimal solution O(N) time complexity O(1) space
C# | Review of my practice in July 2018

  1. Wiggle Sort II
    C# | Using Sorting to find median value

April 22, 2022
295. Find Median from Data Stream
C# | Minimum heap and maximum heap | SortedSet<Tuple<int, int>>

April 19, 2022
11. Container With Most Water
C# | Two pointers technique | Time complexity: O(N)

#MetaOnsite #onsite #Facebook #SystemDesign


Monday, July 3, 2023

Alissa Coram: How To Find And Refine Your Own Trading Style | Investing With IBD

Here is the link. 

Core - Learn the core from Bill 

36:03

  1. Make incremental decision
  2. Trade around core position - 
  3. Trading ETFs and ...
  4. Before market has cleared the direction - 
  5. You will always make mistakes, learn from mistakes, appreciate them. 
  6. Always buy too late, sell too early; Staying on longest
  7. Do not make major mistakes all the time. Just hang out longest time. Stick around longest, participate in ...


守底线, 不猜顶

  现在就努力践行豹哥的6个字: 守底线, 不猜顶


我再解释一下

守底线, 这个有两层含义, 首先第一层, 一定要守底线, 不要让大跌把你的盈利或本钱全吃了。 这样搞到现在还没有回本。第二层, 选股票一定要有底线, 不要想着什么都买, 有些股票要坚决不碰, 如小盘股, 生物股, 金油气, 科幻股, 大部分三倍股, 所有反指, 大麻股, 最简单的就是QQQ, SPY, NVDA, TSLA, AAPL, MSFT, GOOGL, Amd, meta, Costco. 其余就别碰了。 选这些, 想赔钱都不容易。

不猜顶, 意思就是要有长线思维, 大生意思维, 不要进进出出, 每天都是紧张亏了赚了, 买一个好股票, 一定要以月为单位, 最好以年为单位。

Make rules

  1. 坚决不碰, 如小盘股, 生物股, 金油气, 科幻股, 大部分三倍股, 所有反指, 大麻股
  2. 不要想着什么都买
  3. QQQ, SPY, NVDA, TSLA, AAPL, MSFT, GOOGL, Amd, meta, Costco. 其余就别碰了
  4. 不猜顶
  5. 要有长线思维
  6. 大生意思维
  7. 不要进进出出,  每天都是紧张亏了赚了
  8. 买一个好股票, 一定要以月为单位, 最好以年为单位



守底线, 不猜顶

 现在就努力践行豹哥的6个字: 守底线, 不猜顶


我再解释一下

守底线, 这个有两层含义, 首先第一层, 一定要守底线, 不要让大跌把你的盈利或本钱全吃了。 这样搞到现在还没有回本。第二层, 选股票一定要有底线, 不要想着什么都买, 有些股票要坚决不碰, 如小盘股, 生物股, 金油气, 科幻股, 大部分三倍股, 所有反指, 大麻股, 最简单的就是QQQ, SPY, NVDA, TSLA, AAPL, MSFT, GOOGL, Amd, meta, Costco. 其余就别碰了。 选这些, 想赔钱都不容易。

不猜顶, 意思就是要有长线思维, 大生意思维, 不要进进出出, 每天都是紧张亏了赚了, 买一个好股票, 一定要以月为单位, 最好以年为单位。

David Saito-Chung | IBD | Harvard university | Book writer

 Here is the link. 

About

Investor's Business Daily and the Making of Millionaires Hardcover – Illustrated, Aug. 24 2004

 Bill O'Neil is a legend to individual investors everywhere. The Wall Street maverick founded Investor's Business Daily, which created a new generation of investor by providing carefully researched investment rules for targeting emerging growth, buying at the right time, and applying sell rules that ensure the greatest profit. Two decades later, IBD is a runaway success, and O'Neil continues to regularly beat the market at its own game.

Investor's Business Daily and the Making of Millionaires is a behind-the-scenes look at O'Neil and the growth of IBD. It describes how investors can use the paper's rich stock market data and focus on growing companies to amass huge stock market gains as it details:

  • O'Neil's legendary CANSLIM stock-picking system
  • Where the next opportunities could be coming from
  • How anyone can take on the leaders and win

    To view the errata sheet for this book, please visit:

    http://books.mcgraw-hill.com/business/download/InvestorsBusiness/

David Chung: Bill O'Neil And The Making Of Millionaires | Investing With IBD

Here is the link.

  1. Cut a lot of small losses - maximum 8%, normally 5% 
  2. 60% success rate, it can bring to the bank. Let one biggest to run
  3. High quality, truly growth stock
  4. Learn from tennis lesson, one good shot but not ready for next shot - get ready for next winning stock
  5. Related to the book I wrote - 20 years IBD, 2004, it took 20 years to become profitable - Patience and concentration, 25 million on two stocks, and then it starts the paper - investor's business daily. 
  6. the fifth lesson - Patience and concentration


Bill O' Neil's legacy

I like to learn Bill O'Neil's legacy - cut loss at 7%, no excuse. 





Mark Minervini On Bill O'Neil's Legacy & Lessons Learned | Trader Tales With IBD | Alissa Coram

Here is the link. 



Sunday, July 2, 2023

Interview with William J. O'Neil

Here is the link.

Kate Stalter interviews IBD Founder Bill O'Neil on his new book, "How To Make Money In Stocks" June 10, 2009

CAN SLIM Rules And How They Were Developed

Here is the link. 

O'Neil gives you the history behind the CAN SLIM strategy and key rules.

The Story Of William O’Neil: Legendary Investor & IBD Founder | IBD

Here is the link. 


Friday, June 30, 2023

Bed Bug Bites: Symptoms, Facts & Natural Treatments

 

Apply Diatomaceous Earth

Another natural bug-repelling substance, diatomaceous earth (DE), is made up of fossilized remains of tiny, aquatic organisms called diatoms. It usually comes in the form of a white powder and is also used in water filtering, food manufacturing, skin products and farming to naturally eliminate free radicals, viruses, insects, parasites and other harmful organisms.

DE contains silica, which has been found in studies to kill insects by removing a portion of the razor-thin, waxy outer coating that helps the insects conserve moisture and survive. It essentially dries them up from inside without the use of chemicals and tends to be more effective than products that rely on abrasion or poisoning.

Sprinkle DE powder where needed in your home, rub the powder into fabrics/your carpets with a brush or broom, and then let the powder sit for about four to 12 hours before vacuuming. It’s recommended that you repeat this process once a week for a total of three to four weeks.

Thursday, June 29, 2023

被裁之后必须放低期待尽快转型

 被裁之后必须放低期待尽快转型。


阿里被裁员的这一波,大厂的高管和中层必须要找到自己转型这条路。


放平心态,而且要降低开支,必须要极致的开源节流,而且要去自己创业,拿到自己创业的结果。


没有任何人可以给你月薪5万块钱。


必须要放低期待,必须要拿到自己的一个当老板的现金流,你才能回到原先的一个生活状态。


互联网进入微利时代,而不是一个红利时代的这样一个年代。


互联网微利时代意味着无论是大厂还是小公司。


都没有任何的刚性预算来给你付10 万 5 万的高薪。


你需要自己成全自己,你需要自己做 50万年收入的小个体户, 100 万年收入的小个体户。