Monday, June 24, 2019

How to Develop a Thick Skin and Not Take Things Personally

Here is the link.


Mastering your mean girl: The No-BS guide to silencing your inner critic and become wildly wealthy, fabulously healthy, and bursting with love

Here is the book on Amazon.com

Here is the interview video.


10 Ways To Gain Independence As A Woman

Here is the article.


1. Spend some time reflecting upon yourself
2. Learn to enjoy alone time
3. Understand your finances
4. Change your vocabulary
5. Understand your own words, needs and desires
6. Know your strengths and weaknesses and play to them
7. Get to know your personality
8. Make yourself a priority
9. Be assertive
10. Learn how to forgive, yourself included


12 Things Strong, Independent Girls Don’t Do

1. They don’t neglect their careers.
2. They don’t fail to handle their own situations.
3. They don’t overreact to bad situations or mistakes.
4. They don’t rise to the bait of haters.
5. They don’t stop learning.
6. They don’t act on first impulse.
7. They don’t let other people affect their confidence.
8. They don’t neglect their physical needs.
9. They don’t have unrealistic expectations.
10. They don’t stay in toxic relationships.
11. They don’t let someone else dictate their relationships.
12. They don’t lose control of their lives.

More patience on problem solving

June 24, 2019

Introduction


Now it is 12:11 AM. I spent a busy weekend to prepare online code assessment, last Saturday I reviewed backtracking pattern, and worked on a few algorithms. I also like to write something based on my review of those algorithms and practice before 2019.

More patience


I think that I should show more passion on algorithm problem solving. I should write down the case study, work on a test case, explain the algorithm using my own words.

I should demonstrate the passion of learning, hard working, excellent attitude when I solve the algorithm. I need to work hard and also need to learn how to write good post on Leetcode.com discuss.


Sunday, June 23, 2019

Case study: Par 401 K portfolio update

June 23, 2019

Introduction


It is my personal finance research. I have to push myself to learn behavior finance, and learn how to be a successful investor. I need to go over my Par IRA portfolio ( called Siva portfolio) and make sure that I am on the right track starting from May 2019.

Case study


Now I have 2.5% YTD return. I need to learn how to save time and also monitor the porfolio. How to prepare the bear market?



Last 10 years performance



401 K fund performance




How I spent a Sunday to review Leetcode algorithms?

June 23, 2019

Introduction


It is very stressful day to plan and work on Leetcode algorithm. I spent one hour to take a walk around neighborhood, and then I started to work on Leetcode algorithms, prepare to take an online assessment.

Algorithms to review

Time line:
10:00 PM - get up from bed
12:00 PM - 1:00 PM take a walk
1:00 PM - 7:10 PM study leetcode algorithms

9:00 PM - 10:30 PM take online code assessment

I tried a few things, and then I decided to go over one of Amazon engineer's github folder about Leetcode algorithm.

I chose to go over algorithms in the folder of Amazon, BFS, and Graph.




What is Behavioral Finance?

Here is the link.

#1 Self-Deception
The concept of self-deception is a limit to the way we learn. When we mistakenly think we know more than we actually do, we tend to miss information that we need to make an informed decision.

#2 Heuristic Simplification
We can also scope out a bucket that is often called heuristic simplification. Heuristic simplification refers to information-processing errors.

#3 Emotion
Another behavioral finance bucket is related to emotion, but we’re not going to dwell on this bucket in this introductory session. Basically, emotion in behavioral finance refers to our making decisions based on our current emotional state. Our current mood may take our decision making off track from rational thinking.

#4 Social Influence
What we mean by the social bucket is how our decision making is influenced by others.

Top 10 Biases in Behavioral Finance

Behavioral finance seeks an understanding of the impact of personal biases on investors. Here is a list of common financial biases.
Common biases include:
  1. Overconfidence and illusion of control
  2. Self Attribution Bias
  3. Hindsight Bias
  4. Confirmation Bias
  5. The Narrative Fallacy
  6. Representative Bias
  7. Framing Bias
  8. Anchoring Bias
  9. Loss Aversion
  10. Herding Mentality

Overcoming Behavioral Finance Issues

There are ways to overcome negative behavioral tendencies in relation to investing. Here are some strategies you can use to guard against biases.
#1 Focus on the Process
There are two approaches to decision-making:
  • Reflexive – Going with your gut, which is effortless, automatic and, in fact, is our default option
  • Reflective – Logical and methodical, but requires effort to engage in actively
Relying on reflexive decision-making makes us more prone to deceptive biases and emotional and social influences.
Establishing logical decision-making processes can help protect you from such errors.
Get yourself focused on the process rather than the outcome. If you’re advising others, try to encourage the people you’re advising to think about the process rather than just the possible outcomes. Focusing on the process will lead to better decisions because the process helps you engage in reflective decision-making.

#2 Prepare, Plan and Pre-Commit
Behavioral finance teaches us to invest by preparing, by planning, and by making sure we pre-commit. Let’s finish with a quote from Warren Buffett.
“Investing success doesn’t correlate with IQ after you’re above a score of 25. Once you have ordinary intelligence, then what you need is the temperament to control urges that get others into trouble.”
Learn more in CFI’s Behavioral Finance Course!

Additional Resources

Thank you for reading this CFI introductory guide to behavioral finance. CFI is on a mission to help anyone become a world-class financial analyst with the Financial Modeling & Valuation (FMVA) certification. To continue learning, these resources will be useful:


Leetcode BFS algorithms

June 23, 2019

It is a good idea to go over all BFS algorithms together. Here is the github folder to contain all algorithms.

BFS algorithms

I spent a few hour to go over all those 21 algorithms.




815. Bus Routes

It is a hard level algorithm. I spent 20 minutes to read all kind of solutions. I will take some time to work on the algorithm.

It should be a fun journey to solve the problem.


Leetcode 541 0 1 matrix

Here is the blog to read.

这道题给了我们一个只有0和1的矩阵,让我们求每一个1到离其最近的0的距离,其实也就是求一个距离场,而求距离场那么BFS将是不二之选。刚看到此题时,我以为这跟之前那道 Shortest Distance from All Buildings 是一样的,从每一个0开始遍历,不停的更新每一个1的距离,但是这样写下来TLE了。后来我又改变思路,从每一个1开始BFS,找到最近的0,结果还是TLE,气死人。后来逛论坛发现思路是对的,就是写法上可以进一步优化,我们可以首先遍历一次矩阵,将值为0的点都存入queue,将值为1的点改为INT_MAX。之前像什么遍历迷宫啊,起点只有一个,而这道题所有为0的点都是起点,这想法,叼!然后开始BFS遍历,从queue中取出一个数字,遍历其周围四个点,如果越界或者周围点的值小于等于当前值加1,则直接跳过。因为周围点的距离更小的话,就没有更新的必要,否则将周围点的值更新为当前值加1,然后把周围点的坐标加入queue.




Leetcode 490 The maze

Here is the blog to read.

There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.
Given the ball's start position, the destination and the maze, determine whether the ball could stop at the destination.
The maze is represented by a binary 2D array. 1 means the wall and 0 means the empty space. You may assume that the borders of the maze are all walls. The start and destination coordinates are represented by row and column indexes.
Example 1
Input 1: a maze represented by a 2D array

0 0 1 0 0
0 0 0 0 0
0 0 0 1 0
1 1 0 1 1
0 0 0 0 0

Input 2: start coordinate (rowStart, colStart) = (0, 4)
Input 3: destination coordinate (rowDest, colDest) = (4, 4)

Output: true
Explanation: One possible way is : left -> down -> left -> down -> right -> down -> right.


Example 2
Input 1: a maze represented by a 2D array

0 0 1 0 0
0 0 0 0 0
0 0 0 1 0
1 1 0 1 1
0 0 0 0 0

Input 2: start coordinate (rowStart, colStart) = (0, 4)
Input 3: destination coordinate (rowDest, colDest) = (3, 2)

Output: false
Explanation: There is no way for the ball to stop at the destination.


Note:
  1. There is only one ball and one destination in the maze.
  2. Both the ball and the destination exist on an empty space, and they will not be at the same position initially.
  3. The given maze does not contain border (like the red rectangle in the example pictures), but you could assume the border of the maze are all walls.
  4. The maze contains at least 2 empty spaces, and both the width and height of the maze won't exceed 100.

这道题让我们遍历迷宫,但是与以往不同的是,这次迷宫是有一个滚动的小球,这样就不是每次只走一步了,而是朝某一个方向一直滚,直到遇到墙或者边缘才停下来,我记得貌似之前在手机上玩过类似的游戏。那么其实还是要用DFS或者BFS来解,只不过需要做一些修改。先来看DFS的解法,我们用DFS的同时最好能用上优化,即记录中间的结果,这样可以避免重复运算,提高效率。我们用二维数组dp来保存中间结果,然后用maze数组本身通过将0改为-1来记录某个点是否被访问过,这道题的难点是在于处理一直滚的情况,其实也不难,只要我们有了方向,只要一直在那个方向上往前走,每次判读是否越界了或者是否遇到墙了即可,然后对于新位置继续调用递归函数,

417. Pacific Atlantic Water Flow 太平洋大西洋水流

Here is the blog to read.

Another one is here.


Leetcode - Amazon

June 23, 2019

It is my forked library, and it is best place for me to warm up algorithms before I take any weekly contest, or online code assessment etc.

Here is the link.


Leetcode - Microsoft

Microsoft (92)
138 Copy List with Random Pointer
348 Design Tic-Tac-Toe
206 Reverse Linked List
419 Battleships in a Board
273 Integer to English Words
171 Excel Sheet Column Number
54 Spiral Matrix
88 Merge Sorted Array
445 Add Two Numbers II
236 Lowest Common Ancestor of a Binary Tree
200 Number of Islands
53 Maximum Subarray
1 Two Sum
235 Lowest Common Ancestor of a Binary Search Tree
186 Reverse Words in a String II
218 The Skyline Problem
21 Merge Two Sorted Lists
116 Populating Next Right Pointers in Each Node
103 Binary Tree Zigzag Level Order Traversal
297 Serialize and Deserialize Binary Tree
238 Product of Array Except Self
121 Best Time to Buy and Sell Stock
268 Missing Number
48 Rotate Image
75 Sort Colors
151 Reverse Words in a String
13 Roman to Integer
73 Set Matrix Zeroes
117 Populating Next Right Pointers in Each Node II
20 Valid Parentheses
141 Linked List Cycle
2 Add Two Numbers
33 Search in Rotated Sorted Array
168 Excel Sheet Column Title
24 Swap Nodes in Pairs
8 String to Integer (atoi)
237 Delete Node in a Linked List
146 LRU Cache
232 Implement Queue using Stacks
173 Binary Search Tree Iterator
98 Validate Binary Search Tree
208 Implement Trie (Prefix Tree)
174 Dungeon Game
212 Word Search II
4 Median of Two Sorted Arrays
5 Longest Palindromic Substring
285 Inorder Successor in BST
153 Find Minimum in Rotated Sorted Array
26 Remove Duplicates from Sorted Array
160 Intersection of Two Linked Lists
106 Construct Binary Tree from Inorder and Postorder Traversal
102 Binary Tree Level Order Traversal
23 Merge k Sorted Lists
25 Reverse Nodes in k-Group
215 Kth Largest Element in an Array
189 Rotate Array
191 Number of 1 Bits
567 Permutation in String
71 Simplify Path
387 First Unique Character in a String
15 3Sum
204 Count Primes
56 Merge Intervals
94 Binary Tree Inorder Traversal
165 Compare Version Numbers
28 Implement strStr()
46 Permutations
300 Longest Increasing Subsequence
91 Decode Ways
101 Symmetric Tree
270 Closest Binary Search Tree Value
114 Flatten Binary Tree to Linked List
79 Word Search
258 Add Digits
125 Valid Palindrome
124 Binary Tree Maximum Path Sum
162 Find Peak Element
112 Path Sum
654 Maximum Binary Tree
333 Largest BST Subtree
365 Water and Jug Problem
452 Minimum Number of Arrows to Burst Balloons
47 Permutations II
513 Find Bottom Left Tree Value
213 House Robber II
55 Jump Game
591 Tag Validator
631 Design Excel Sum Formula
642 Design Search Autocomplete System
650 2 Keys Keyboard
651 4 Keys Keyboard
672 Bulb Switcher II

Leetcode - Amazon

Sorted by frequency of problems that appear in real interviews. 

Last updated: October 2, 2017

Amazon (88)
534 Design TinyURL
675 Cut Off Trees for Golf Event
1 Two Sum
20 Valid Parentheses
146 LRU Cache
438 Find All Anagrams in a String
200 Number of Islands
48 Rotate Image
297 Serialize and Deserialize Binary Tree
138 Copy List with Random Pointer
236 Lowest Common Ancestor of a Binary Tree
460 LFU Cache
387 First Unique Character in a String
121 Best Time to Buy and Sell Stock
239 Sliding Window Maximum
5 Longest Palindromic Substring
17 Letter Combinations of a Phone Number
238 Product of Array Except Self
42 Trapping Rain Water
682 Baseball Game
127 Word Ladder
380 Insert Delete GetRandom O(1)
235 Lowest Common Ancestor of a Binary Search Tree
206 Reverse Linked List
23 Merge k Sorted Lists
155 Min Stack
2 Add Two Numbers
98 Validate Binary Search Tree
449 Serialize and Deserialize BST
240 Search a 2D Matrix II
234 Palindrome Linked List
517 Super Washing Machines
215 Kth Largest Element in an Array
139 Word Break
21 Merge Two Sorted Lists
49 Group Anagrams
126 Word Ladder II
3 Longest Substring Without Repeating Characters
242 Valid Anagram
529 Minesweeper
160 Intersection of Two Linked Lists
141 Linked List Cycle
186 Reverse Words in a String II
167 Two Sum II – Input array is sorted
15 3Sum
78 Subsets
535 Encode and Decode TinyURL
73 Set Matrix Zeroes
102 Binary Tree Level Order Traversal
508 Most Frequent Subtree Sum
8 String to Integer (atoi)
538 Convert BST to Greater Tree
204 Count Primes
199 Binary Tree Right Side View
414 Third Maximum Number
89 Gray Code
451 Sort Characters By Frequency
355 Design Twitter 2
119 Pascal’s Triangle II
662 Maximum Width of Binary Tree
645 Set Mismatch
617 Merge Two Binary Trees
661 Image Smoother
396 Rotate Function
646 Maximum Length of Pair Chain
545 Boundary of Binary Tree
606 Construct String from Binary Tree
640 Solve the Equation
663 Equal Tree Partition
459 Repeated Substring Pattern
516 Longest Palindromic Subsequence
532 K-diff Pairs in an Array
579 Find Cumulative Salary of an Employee
536 Construct Binary Tree from String
537 Complex Number Multiplication
553 Optimal Division

Leetcode - Facebook

Facebook (111)
534 Design TinyURL
283 Move Zeroes
301 Remove Invalid Parentheses
273 Integer to English Words
325 Maximum Size Subarray Sum Equals k
67 Add Binary
621 Task Scheduler
253 Meeting Rooms II
17 Letter Combinations of a Phone Number
311 Sparse Matrix Multiplication
91 Decode Ways 19.8%
297 Serialize and Deserialize Binary Tree
314 Binary Tree Vertical Order Traversal
10 Regular Expression Matching
15 3Sum
158 Read N Characters Given Read4 II – Call multiple times
278 First Bad Version
277 Find the Celebrity
200 Number of Islands
76 Minimum Window Substring
257 Binary Tree Paths
282 Expression Add Operators
23 Merge k Sorted Lists
157 Read N Characters Given Read4
121 Best Time to Buy and Sell Stock
602 Friend Requests II: Who Has the Most Friends
56 Merge Intervals
161 One Edit Distance
173 Binary Search Tree Iterator
1 Two Sum
543 Diameter of Binary Tree
211 Add and Search Word – Data structure design
341 Flatten Nested List Iterator
252 Meeting Rooms
125 Valid Palindrome
597 Friend Requests I: Overall Acceptance Rate
139 Word Break
636 Exclusive Time of Functions
285 Inorder Successor in BST
78 Subsets
98 Validate Binary Search Tree
43 Multiply Strings
75 Sort Colors
670 Maximum Swap
57 Insert Interval
133 Clone Graph
215 Kth Largest Element in an Array
33 Search in Rotated Sorted Array
13 Roman to Integer
206 Reverse Linked List
79 Word Search
494 Target Sum
236 Lowest Common Ancestor of a Binary Tree
398 Random Pick Index
477 Total Hamming Distance
38 Count and Say
680 Valid Palindrome II
49 Group Anagrams
88 Merge Sorted Array
218 The Skyline Problem
146 LRU Cache
238 Product of Array Except Self
209 Minimum Size Subarray Sum
102 Binary Tree Level Order Traversal
90 Subsets II
71 Simplify Path
286 Walls and Gates
128 Longest Consecutive Sequence
639 Decode Ways II
523 Continuous Subarray Sum
334 Increasing Triplet Subsequence
208 Implement Trie (Prefix Tree)
28 Implement strStr()
269 Alien Dictionary
127 Word Ladder
647 Palindromic Substrings
377 Combination Sum IV
20 Valid Parentheses
44 Wildcard Matching
554 Brick Wall
235 Lowest Common Ancestor of a Binary Search Tree
380 Insert Delete GetRandom O(1)
50 Pow(x, n)
117 Populating Next Right Pointers in Each Node II
69 Sqrt(x)
461 Hamming Distance
85 Maximal Rectangle
210 Course Schedule II
26 Remove Duplicates from Sorted Array
68 Text Justification
221 Maximal Square
274 H-Index
404 Sum of Left Leaves
25 Reverse Nodes in k-Group
234 Palindrome Linked List
689 Maximum Sum of 3 Non-Overlapping Subarrays
80 Remove Duplicates from Sorted Array II
168 Excel Sheet Column Title
261 Graph Valid Tree
265 Paint House II
275 H-Index II
410 Split Array Largest Sum
525 Contiguous Array
674 Longest Continuous Increasing Subsequence
572 Subtree of Another Tree
578 Get Highest Answer Rate Question
637 Average of Levels in Binary Tree
642 Design Search Autocomplete System
653 Two Sum IV – Input is a BST
673 Number of Longest Increasing Subsequence
535 Encode and Decode TinyURL