Jan. 23, 2021
Here is the link.
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
Jan. 23, 2021
Here is the link.
Jan. 23, 2021
I do not know very well the community parking along the street until a real estate agent talked to me. I also learned that two bedroom home costs $710,000 dollars on the market right now.
One condo on sale
Real Estate Advisor/REALTOR®
C 604-240-6015
T 604-224-5277
Here is the link.
MLS# R2529649
Jan 22, 2021
Here is the link.
I spent near one hour to evaluate search product features of home depot. I learned a few things. I need to purchase a glasstop electronic range. I thought about Amazon customer obsession leadership, and I think that it is better for me to replace a new range for the renter.
Two coils are working, but the renter said only one is working. It is hard for me to argue since I live in Canada, the renter is in Florida.
Jan. 22, 2021
Introduction
It is important for me to learn how to sort priority. I was thinking about my rental property - a range, looked up bestbuy and home depot. But I did not set priority, purchased $10,000 US dollar EXPR stock as I made plans several time. I like to write down my story as an investor.
EXPR stock - up from $1.1/ share to $2.7/ share
I like to document the process, and will come back to learn from my own experience.
Jan. 21, 2021
Here is the link.
With all the announced stimulus, the FED's balance sheet going to $10 trillion, it is time to discuss Inflation and perhaps even hyperinflation. Government deficits are huge and will be only growing, thus currencies have to be debased! There is no other way. So, protect yourself and own real assets. This is also the reason why stocks have been going up even as we are entering the mother of all recessions. When it comes to the stock market, investing in stocks, looking for inflation protection, it is always about real assets. Enjoy the stock market news for today. Want to know more about my research and portfolios? Here is my independent stock market analysis and research! STOCK MARKET RESEARCH PLATFORM (analysis, stocks to buy, model portfolio) https://sven-carlin-research-platform...
Financial stimulus - Inflation - sideline - park everywhere - even more printing - into the market
Stock overvalue -
Jan. 21, 2021
Here is the link.
Jan. 21, 2021
Introduction
It is the last algorithm in Leetcode premium Microsoft mock onsite. I could not finish the code in mock interview. I understood that it can be solved using brute force all possible subproblems using two dimension dynamic programming.
Case studies
It is important for me to play with the following test cases first, understand the value of minimum move, and then write a solution to match the analysis.
Case 1:
[1, 3, 4, 1], it should be 2, not 3. I wrote the code and then failed the test case by online judge. And then I learned to analyze the case. Remove 4, [1, 3, 1] should be able to be removed once since it is palindrome.
Case 2:
[1, 3, 4, 1, 5], it should be 3, not 4. One of solutions is to remove 4 first, then remove [1, 3, 1], and then remove [5].
Lessons I learn:
Time spent
I spent more than two hours to make it work. It is important for me to work independently, since I already solved over 600 algorithms. I like to trian myself to think hard, longer, and solve a hard level algorithm by myself.
Continue to simplify
After the first success submission and writing of this post, I spent another 15 minutes to simplify the code, remove redudant code, and make it concise and working.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace minimumMove
{
class Program
{
static void Main(string[] args)
{
//var result = MinimumMoves(new int[]{1, 3, 4, 1});
//var result = MinimumMoves(new int[] { 1, 3, 4, 1, 5 });
var result = MinimumMoves(new int[] { 19, 4, 9, 11, 19 });
}
/// <summary>
/// Leetcode - 1246. Palindrome Removal
/// </summary>
/// <param name="arr"></param>
/// <returns></returns>
public static int MinimumMoves(int[] arr)
{
if (arr == null || arr.Length == 0)
return 0;
var n = arr.Length;
var dp = new int[n, n];
dp[0, 0] = 1;
for (int end = 1; end < n; end++)
{
// dp[0, end], ..., dp[end - 1, end] backward
dp[end, end] = 1;
for (int i = 1; i <= end; i++)
{
var left = end - i;
var right = end;
// [1, 3, 4, 1], dp[0, 3] = 2, not 3,
var bothEndSame = arr[left] == arr[right];
var count = right - left + 1;
var min = count;
var dpCenter = 0;
if (count > 2)
{
dpCenter = dp[left + 1, right - 1]; // exclude both ends
}
min = 2 + dpCenter;
if (bothEndSame)
{
min = dpCenter; // [1, 2, 3, 4, 1]
if(count == 2)
{
min = 1;
}
}
for (int k = left + 1; k <= end; k++) // [1, 3, 4, 1, 5] -> dp[0, 3] + dp[4, 4]
{
min = Math.Min(min, dp[left, k - 1] + dp[k, end]);
}
dp[left, end] = min;
}
}
return dp[0, n - 1];
}
}
}
Jan. 21, 2021
Here is the link.
Jan. 21, 2021
Introduction
It is my first algorithm in Microsoft mock onsite. It took me over 20 minutes to calm down, and I like to simplify my solution, avoid so many if case.
Case study
"abc" is chosen to replace all '?' chars, since there is at most two neighbors for any '?' char, it is working to find one char left after removing those two neighbor chars.
I thought about cases if there is left neighbor or right neighbor, if it is '?' or not. I think that it is better to remove two neighbor chars, first one left will be chosen.
It is my way to replace. I wish that I can solve it in less than 10 minutes. But in reality, I took two days break to practice mock onsite. I tried to learn one hard level in my previous one. I have hard time to focus and think quickly.
The following code passes online judge.
public class Solution {
public string ModifyString(string s) {
if(s == null || s.Length == 0)
{
return "";
}
var arr = s.ToCharArray();
var length = s.Length;
for(int i = 0; i < length; i++)
{
var current = s[i];
var empty = current == '?';
var replaced = new HashSet<char>("abc".ToCharArray());
if(!empty)
{
continue;
}
if(i > 0)
{
replaced.Remove(arr[i - 1]);
}
if(i < length - 1)
{
replaced.Remove(arr[i + 1]);
}
arr[i] = replaced.ToList()[0];
}
return new string(arr);
}
}
Jan. 21, 2021
Here is the link.
Jan. 21, 2021
Introduction
It is very good practice although I made it work in less than 48 minutes in mock onsite interview - Microsoft. I spent over 15 minutes to think about how to find any light should be set to blue using O(1) time, just check it's left neighbor.
Design issue
It took me at least 10 minutes to figure out how to use O(1) to check if the current light can set to blue or not.
The status array is declared to store all position light status, 0 - off, 1 - on, 2 - blue.
Any light can be changed from 'on'(1) to 'blue'(2) only once. It is easy to argue and prove it. When a light is set to blue, the right neighbor should be checked one by one if needed to change from on to blue.
For example, [2, 1, 3, 5, 4]
First light is at position of index = 1, second light is at position of index = 0 which should be blue (no left neighbor). Next to check it's right, index = 1, status[1] = 1, change it to 2.
Performance
It took me over 20 minutes to fix bugs. I mixed variable current with i inside for loop. It is better for me to name current variable with meaningful name to avoid mixing with i.
The current variable should be better named as placeHolder, left neighbor is placeHolder - 1, right neighbor is placeHolder + 1. I will think more later for better naming.
Time complexity
O(N), N is the length of the array
Space complexity
O(N), N is the length of the array
The following code passes online jduge
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TurnOnLights
{
class Program
{
static void Main(string[] args)
{
var light = new int[] { 1, 6, 3, 4, 5, 7, 2, 8, 9, 10 };
var result = NumTimesAllBlue(light);
}
public static int NumTimesAllBlue(int[] light)
{
if (light == null || light.Length == 0)
{
return 0;
}
var length = light.Length;
var status = new int[length]; // 0 - off, 1 - on, 2 - blue
var count = 0;
for (int i = 0; i < length; i++)
{
var current = light[i] - 1;
status[current] = 1;
if (current == 0 || (status[current - 1] == 2)) // mix i with current - take 10 minutes
{
status[current] = 2;
//check right neighbors
var index = current + 1; // mix i with current
while (index < length && status[index] == 1)
{
status[index++] = 2;
}
if (index == (i + 1))
{
count++;
}
}
}
return count;
}
}
}