Thursday, October 31, 2019

Case study: my mock interview as an interviewee on Oct. 31, 2019

Oct. 31, 2019

Introduction


I had a mock interview today at 10:00 PM, and I like to write case study of my mock interview. It is important for me to learn how to pass mock interview on interviewing.io.

Case study


The code I wrote for the first algorithm.
Extended algorithm

Interviewer feedback



Actionable Items

Follow up
Nov. 2, 2019

My ranking of interviewer does not match the feedback I wrote about the interviewer. I should lower the ranking of interviewer, at most 3. I have to learn how to make decision based on my careful consideration first.

Do not give the interviewer rank 4, which should be 2, not as good as 3.


Case study: mock interview August 5, 2019 interviewee Serial Lambda

Oct. 31, 2019

Introduction


It is such a good interview and I like to work on a case study on this mock interview. I like the interviewer and how he gave out hints, and the communication between two engineers. The mock interview is on August 5, 2019 Serial Lambda - interviewee.

Case study

The algorithms asked in the interview are Leetcode 941, and Leetcode 1055.

I really like the learning experience to watch the interview. I also like the algorithm since I could not figure out the algorithm at the beginning without his hint.

It is a good idea to preprocess the source string into a hashmap first.




475. Heaters

Here is the link.

C# binary search to avoid timeout issue

It is an easy level algorithm, so I wrote the brute force solution first, and then I came cross timeout issue. I learn to write a binary search algorithm to expedite the process to find minimum value.
To understand C# Array.BinarySearch, it is also necessary to understand return index with negative value of BinarySearch API.
Time complexity: maximum of values {nlogn, mlogm, nlogm}, n is length of houses, m is length of heaters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _475_heaters___binary_search
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = FindRadius(new int[]{1, 2, 3}, new int[]{2}); 
        }

        /// <summary>
        /// 475 heaters
        /// binary search review 
        /// https://docs.microsoft.com/en-us/dotnet/api/system.array.binarysearch?view=netframework-4.8
        /// If the Array does not contain the specified value, the method returns a negative integer. 
        /// You can apply the bitwise complement operator (~ in C#, Not in Visual Basic) to the 
        /// negative result to produce an index. If this index is one greater than the upper bound 
        /// of the array, there are no elements larger than value in the array. Otherwise, it is 
        /// the index of the first element that is larger than value.
        /// 
        /// Time complexity: maximum of values {nlogn, mlogm, nlogm}, n is length of houses, m is length of heaters
        /// </summary>
        /// <param name="houses"></param>
        /// <param name="heaters"></param>
        /// <returns></returns>
        public static int FindRadius(int[] houses, int[] heaters)
        {
            if (houses == null || houses.Length == 0 ||
                heaters == null || heaters.Length == 0)
            {
                return 0;
            }

            var minumumRadius = Int32.MinValue;

            Array.Sort(houses);
            Array.Sort(heaters); 

            foreach (var item in houses)
            {
                // For each house, find minimum distance to one of heaters
                var minimumValue = Int32.MaxValue;

                var index = Array.BinarySearch(heaters, item);

                var length = heaters.Length;

                if (index >= 0)  /* should be >=, not > - caught by online judge */
                {
                    minimumValue = 0;
                }
                else
                {
                    var firstLarger = ~index; /* ~ complement operator */
                    if (firstLarger >= heaters.Length)
                    {
                        minimumValue = Math.Abs(item - heaters[length - 1]);
                    }
                    else
                    {
                        minimumValue = Math.Abs(item - heaters[firstLarger]);
                        if (firstLarger - 1 >= 0)
                        {
                            minimumValue = Math.Min(Math.Abs(item - heaters[firstLarger - 1]), minimumValue); 
                        }                       
                    }
                }

                // From all houses, choose maximum one from the distance to heater.
                if (minimumValue > minumumRadius)
                {
                    minumumRadius = minimumValue;
                }
            }

            return minumumRadius;
        }
    }
}


Two hours fitness training every day

Oct. 31, 2019

Introduction


It is my bias to try to hide my age, and things I have to learn to deal with 53 years old brain and physical strength. I wish that I can spend one or two hours every day to play sports, warm up every big muscle, and do a lot of conditioning training to keep myself fit and also stay in good shape.

Two hours fitness training


I like to figure out how I can do two hours fitness training every day.



Personality weakness

Oct. 30, 2019

Introduction


It is my short research. I like to figure out how to be a good interviewer on interviewing.io, so I decide to study all show case interviews.

My weakness


I have some weakness as an interviewer. I need to learn how to give interviewee full spectrum of scores, 1 to 4.  I was scared to give people low rating since I thought I may hurt people's feelings.






Wednesday, October 30, 2019

530. Minimum Absolute Difference in BST

Here is the link.

C# Inorder traversal solution

Oct. 30, 2019
To traverse the binary search tree in ascending order, inorder traversal is chosen. Inorder traversal is to visit left node, root node and then right node. The previous node is declared as static variable, to work with more than one test cases, it is important to reset previous node to null.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _530_minimum_difference_in_BST
{
    class Program
    {
        public class TreeNode {
            public int val;
            public TreeNode left;
            public TreeNode right;
            public TreeNode(int x) { val = x; }
        }

        static void Main(string[] args)
        {
            var node1 = new TreeNode(1);
            var node5 = new TreeNode(5);
            var node3 = new TreeNode(3);

            node1.right = node5;
            node5.left = node3;

            var result = GetMinimumDifference(node1); 
        }

        static TreeNode previous;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="root"></param>
        /// <returns></returns>
        public static int GetMinimumDifference(TreeNode root)
        {
            previous = null;  // caught by online judge - Oct. 30, 2019
            int minDiff = Int32.MaxValue;
            traverseInorder(root, ref minDiff);
            return minDiff;
        }

        /// Left, Root, right
        private static void traverseInorder(TreeNode root, ref int minDiff)
        {
            if (root == null)
                return;
            traverseInorder(root.left, ref minDiff);

            // handle root node
            if (previous != null)
            {
                var current = root.val - previous.val;
                minDiff = current < minDiff ? current : minDiff;
            }

            previous = root;

            traverseInorder(root.right, ref minDiff);
        }
    }
}


8 tree algorithms to practice

Oct. 30, 2019

Introduction


It is my most favorite job in the world to solve tree algorithms. There are 6 medium level tree algorithms and 2 hard level algorithms available for me to solve. I am so excited and look forward to best learning experience in short future.

Tree algorithms


Here are those tree algorithms I like to solve.

Hard level, 968, 1028
Medium level, 117, 116, 1145, 1130, 1123, 1104




5 Ways The Rich Build Wealth That The Poor Don't | How To Get Rich From Nothing

Here is the link.


Studio 1.0: Mark Zuckerberg

Here is the link.


Interviewing.io showcase study

Oct. 30, 2019

Introduction


It is time of year I like to search good ideas, and I like to find time to solve more easy level algorithms or medium level on Leetcode.com next two months. One of ideas is to study time to review all showcases on interviewing.io. I like to learn from other interviewers and interviewees.


Showcases


I like to write down some notes about my study. I like to take time to watch, and also try to evaluate how good interviewers are.


450 mark - I just solved 450 Leetcode algorithms

Oct. 30, 2019

Introduction


I just spent less than 30 minutes to solve one easy level tree algorithm, so I just reached 450 mark. In other words, I just solved 450 algorithms on leetcode.com. Unbelievable.

My 450 mark


Here is the algorithm I just solved which is an easy level tree algorithm. I solved 9 easy level algorithms tagged with array last week. I learned to write easy ones in order to push myself with busy schedule - a full time job.

I just like to showoff my mark - 450 solved algorithm.


It is such a bargain, in order to solve more algorithms, I choose to solve easy level ones first. I do believe that I can learn much better through easy level ones.




Facebook Hackathon; Mark Zuckerberg showing what his team has built

Here is the link.


Tuesday, October 29, 2019

14 SUREFIRE WAYS TO IMPROVE YOUR FINANCES IN 2020

Here is the article.

12. EDUCATE YOURSELF

An investment in knowledge pays the best interest. – Benjamin Franklin
Increase your knowledge and improve your skills by continuously reading and learning. Investing in yourself is one of the most important investments you will ever make. Through education, you may be able to: increase your income-earning ability, increase your capacity to provide solutions to real-life problems, broaden your general understanding and thinking ability, and feel fulfilled and satisfied with your life.
In the area of finances, there are many personal finance books you can read this year to increase your understanding of investing, debt management, budgeting, and more, including:
The Automatic Millionaire by David Bach: This is a clear guide on how to build wealth and financial freedom on any income.
I will Teach You How To Be Rich by Ramit Sethi: A six-week program that shows millennials (20- to 35-year olds) how to master their money easily.
The Total Money Makeover by Dave Ramsey: This book shows you how to beat crushing debt!
The Little Book of Common Sense Investing by John Bogle: Written by the father of index investing, the book gives you insight into how simplified investing pays best.
The Richest Man in Babylon by George Clason: See how ancient financial truths still hold sway in today’s world.

【Netflix 纪录片 双语字幕可选 】走进比尔:解码 比尔·盖茨 2

Here is the link.

NVIDIA Shares Are Surging With Huge Demand

Here is the article.

A gain of 53.07% in 2019 for shares of NVIDIA Corporation (NVDA) tells a story of big buy demand lifting the shares. This buying is very unusual and has been happening very recently. As the move to 5G ramps up, some semiconductor stocks could be rewarded handsomely. We think the rush for this group is happening now. A great way to uncover tomorrow's winners is to look for great stocks seeing big buy activity, and NVIDIA could be just the opportunity.

I wish that I learn that NVIDIA stock is the good choice to purchase.

53.07%
53.07%
53.07%
53.07%
53.07%

Why Your Realistic Goals Are Holding You Back

Here is the link.

How to Radically Change Your Goals and Success

Here is the article.

Are you living 10X?

"Being careful requires you to take actions cautiously--and there is no way that you will ever hit 10X activity levels by being cautious." ― Grant Cardone
Look at your goals for 2016. Chances are, they reflect timid thinking and less-than-creative planning. Without question, your goals are less challenging than you can handle. You are more than you know. You can handle more than you think. You can adapt to anything.
As an example, if your goal is to earn $50,000 in 2016, I challenge you to change that goal to $500,000.
When you 10X your goals, you will be forced to approach your goal in non-conventional and innovative ways. The traditional approach doesn't work with 10X thinking.
Not only does your mind need to expand in what you plan and strive for, but your daily effort needs to change as well. Just as people underestimate their personal ability, they also underestimate how much effort and time something will take. Thus, people are frequently late for appointments and fail to complete projects they begin.
Rather than expecting ideal circumstances, plan for the worst. Rather than underestimating how much time and effort something will take, over estimate those things. Put way more effort into your goal than you think is required to get there.
If you're going to think 10X, you have to also put in 10X effort. Without the effort, it doesn't matter how "big" your dreams are. But once your behavior matches (and exceeds) your intentions, your dreams quickly become a reality.


The 10X Rule by Grant Cardone

Here is the summary.

  • Limiting the amount of success you desire is a violation of the 10X Rule.
  • The 10X Rule: You must set targets for yourself that are 10X more than what you think you want and then take 10X the action you think is required to get there.
  • Common mistake 1: setting your sights too low.
  • Common mistake 2: underestimating how much action is required.
  • Common mistake 3: spending too much time competing and not enough time dominating their sector.
  • Common mistake 4: underestimating the amount of adversity they will have to overcome.
  • Any goal you set is going to be difficult to achieve, so why not set them higher from the beginning?
  • Most people feel like they are working – rather than chasing passion – because the payoff isn't large enough.
  • You will either work to accomplish your goals and dreams or you'll be used to accomplish someone else's goals and dreams.
  • Never reduce a target. Do not explain away failure. Always increase your actions.

10 x high goals

Oct. 29, 2019

Introduction

It is my personal finance research. I did review those videos about the book 10 X rule. I like to figure out how to apply the idea to my personal situation.


1239. Maximum Length of a Concatenated String with Unique Characters

Here is the link.

C# A solution with readable code using DFS

It is the algorithm which can be solved using depth first search. I like to practice and also make the code easy to write and readable.
Here are highlights:
  1. Design depth first search and recursive function with four arguments;
  2. default empty string is considered as a unique string with my defined isUnique function;
  3. Depth first search algorithm is to go through all possible paths starting from a list from 0 to length - 1;
  4. isUnique function is implemented to compare a hashSet's count to string's length.
Follow up
I did not come out the solution in weekly contest 160 on Oct. 26, 2019. It is a simple brute force DFS solution. I will look into how to improve performance on weekly contest.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1239_maximujm_length
{
    class Program
    {
        static void Main(string[] args)
        {
        }

        /// <summary>
        /// Oct. 29, 2019
        /// study code
        /// 1239 Maximum length of concatenated string with unique characters
        /// My ideal solution is to write a DFS solution which can easily be understandable, 
        /// and also it can be written in less than 15 minutes. 
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public int MaxLength(IList<string> arr)
        {
            var maxLength = 0;

            runDFS(arr, ref maxLength, 0, "");

            return maxLength; 
        }

        private static void runDFS(IList<string> array, ref int maxLength, int index, string path)
        {
            if (!isUnique(path))
            {
                return;
            }

            var current = path.Length;
            maxLength = current > maxLength ? current : maxLength;

            for (int i = index; i < array.Count; i++)
            {
                runDFS(array, ref maxLength, i + 1, path + array[i]);
            }
        }

        private static bool isUnique(string path)
        {
            var hashSet = new HashSet<char>(path);
            return path.Length == hashSet.Count(); 
        }
    }
}


989. Add to Array-Form of Integer

Here is the link.

Oct. 29, 2019
It is hard to write an iterative solution first time without a bug. I choose to study one of iterative solution, but I do think that it is better for me to add an extra variable called sum, and then work on its calculation.
The code is written in the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _989_Add_To_Array_Form_III
{
    class Program
    {
        static void Main(string[] args)
        {
        }

        /// <summary>
        /// 989. Add to Array-Form of Integer
        /// iterative solution
        /// study code
        /// https://leetcode.com/problems/add-to-array-form-of-integer/discuss/234521/C
        /// </summary>
        /// <param name="words"></param>
        /// <param name="chars"></param>
        /// <returns></returns>
        public IList<int> AddToArrayForm(int[] A, int K)
        {
            var length = A.Length;

            var result = new List<int>();

            int index = length - 1;
            while (index >= 0 || K > 0)
            {
                var sum = K % 10;
                sum += (index >= 0 ? A[index] : 0);

                if (sum >= 10)
                {
                    K += 10; 
                }
                
                index--;

                result.Add(sum % 10);
                K /= 10;
            }

            result.Reverse();
            return result;
        }
    }
}


989. Add to Array-Form of Integer

Here is the link.

Oct. 29, 2019
Here are highlights of my practice:
  1. Work on recursive solution. Figure out base cases
  2. Work on rightmost digit in K first, and try to do some basic work for the algorithm. Make sure that it is minimum.
  3. It is the first time I learn to write IEnumerable.Take, and look into how to use IEnumerable.Skip.
Extra sharing of my training thought process
It is my idea to be humble and work on easy level algorithm first. I solved all easy level algorithm (220 easy level algorithm solved) in Dec. 2018. Now there are around 60 new easy level algorithms available released after Dec. 2018, I like to work on those algorithm first, and I chose to work on 9 easy level array algorithms first, continue to work on rest of easy level ones.
image
image
I believe that easy level algorithms are better to train myself compared to those medium level ones.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _989_Add_To_Array_Form
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = AddToArrayForm(new int[]{1, 2, 3, 4}, 34); 
        }

        /// <summary>
        /// Oct 29, 2019
        /// Leetcode 989 Add to array form
        /// recursive solution 
        /// First time I learn to use IEnumberable.Skip and IEnumberable.Take
        /// </summary>
        /// <param name="A"></param>
        /// <param name="K"></param>
        /// <returns></returns>
        public static IList<int> AddToArrayForm(int[] A, int K) 
        {
            if(K == 0)
            {
                return A.ToList(); 
            }
        
            if(A.Length == 0 && K < 10)
            {
                return new int[]{K}.ToList();
            }
        
            var rightmost = K % 10; 
            var rest = K/10; 
            var sum = 0; 
            if(A.Length == 0)
            {
                sum = rightmost;
            }
            else 
            {
                sum = A[A.Length - 1] + rightmost;
            }
        
            var lessThan10 = sum < 10; 
        
            // recursive solution 
            IList<int> list =  new List<int>();
            var value = rest + (lessThan10 ? 0 : 1);
            var aLength = A.Length;

            if (aLength == 0)
            {
                list = AddToArrayForm(new int[0], value);
            }
            else
            {
                list = AddToArrayForm(A.Take(aLength -1).ToArray(), value);
            }

            list.Add(sum % 10);

            return list;                    
        }
    }
}


Work on easy level array algorithms

Oct. 29, 2019

Introduction

It is time to celebrate my 9th easy level array tag algorithm completed. I have 60 easy level algorithms to work on, 9 of them are easy level array tag ones. I do think that if I can write 10 easy level algorithms, I will warm up and improve my performance at work in the long run. 

Extra sharing of my training thought process
It is my idea to be humble and work on easy level algorithm first. I solved all easy level algorithm (220 easy level algorithm solved) in Dec. 2018. Now there are around 60 new easy level algorithms available released after Dec. 2018, I like to work on those algorithm first, and I chose to work on 9 easy level array algorithms first, continue to work on rest of easy level ones.
image
image
I believe that easy level algorithms are better to train myself compared to those medium level ones.

2019 US equity 96 billion in outflows

Here is the article. 

Worth watching: Investors have the money to pump into US stocks, should they desire. US equity funds have seen $96 billion in outflows so far this year, in favor of bond and cash funds, Goldman Sachs pointed out in a recent note to clients.


C# Array's 80 API to review

Oct. 29, 2019


Introduction


It is interesting to use Visual studio, today I spent time to get Array class's APIs in Visual studio, so I write down all properties and methods, and I like to spend 3 minutes for each API. 


Array's APIs


Array's available method and function are listed in the following, 72 options. I like to memorize all of them, and a few words are new to me. I like to get to know those methods first.



0
Add
AddRange
AsReadOnly
BinarySearch
Clear
Contains
ConvertAll
CopyTo
Exists
Find

FindAll
FindIndex
FindLast
FindLastIndex

1
Aggregate
All
Any
AsEnumerable
AsParallel
AsParallel<>
AsQuerable
AsQuerable<>
Average
Average<>
2
Cast<>
Clone
Concat<>
Contain<>
CopyTo<>
Count<>
DefaultIfEmpty
Distinct
ElementAt
ElementAtOrDefault
3
Equals
Except<>
FirstOrDefault<>
First<>
GetEnumerator
GetHashCode
GetLength
GetLongLength
GetLowerBound
GetType
4
GetUpperBound
GetType
GetUpperBound
GetValue
GroupBy
GroupJoin
Initialize
Intersect
Join
Last
5
LastOrDefault
Length
IsFixedSize
IsReadONly
IsSyncrhonized
Max
Max<>
Min
Min<>
OfType<>
6
OrderBy<>
OrderByDescending<>
Rank
Reverse<>
Select<>
SelectMany<>
SequenceEqual<>
SetValue
Single<>
SingleOrDefault<>
7
Skip<>
SkipWhile<>
Sum
Sum<>
SyncRoot
Take<>
TakeWhile
ToArray
ToDictionary
ToList
8
ToLookup
ToString
Union<>
Where<>
Zip