Showing posts sorted by relevance for query Leetcode 212. Sort by date Show all posts
Showing posts sorted by relevance for query Leetcode 212. Sort by date Show all posts

Thursday, September 14, 2017

July 18, 2017 algorithm review

Sept. 14, 2017


Introduction


It is two months ago, I did spend 3 to 4 hours to review my own practice before 8:00 pm. I went over around 30 algorithms, print one by one on the paper, and then read one by one. I really learned from the preparation, and I like to open a folder on my own github, and list all those algorithms I chose to study on July 18, 2017.

It is so interested to know that once I am busy with the study, the nervousness is kind of going away. I did very good one on preparation, and I had great performance later on the evening to complete code in limited time.

Algorithms


Algorithm 1. In order successor
Algorithm 2. Flatten the dictionary
Algorithm 3: HTree
Algorithm 4: Reverse words
Algorithm 5. Find distance binary tree
Algorithm 6. Leetcode 23 Merge K Sorted List
Algorithm 7: Leetcode 37 Sudoku
Algorithm 8: Leetcode 49 Group anagrams
Algorithm 9: Leetcode54 SpiralMatrix
Algorithm 10: Leetcode 72 Edit distance
Algorithm 11: Leetcode 114 Flatten Binary Tee to Linked List
Algorithm 12: Leetcode 212 Word Search II
Algorithm 13: Leetcode 295 Find median for path stream
Algorithm 14: Leetcode 295 median of stream
Algorithm 15. Leetcode 300 Longest Increasing Subsequence
Algorithm 16. Leetcode 416 Partition equal subset sum
Algorithm 17: Leetcode 516 Longest palindrome subsequence
Algorithm 18: Leetcode 605 Can place flowers
Algorithm 19: Binary tree two path same value
Algorithm 20: Leetcode 239 Sliding window maximum
Algorithm 21: Leetcode 57   Insert interval
Algorithm 22: Leetcode 10   Regular expression matching
Algorithm 23: Leetcode 547 Find Circle
Algorithm 24: Leetcode 130 Surrouned region
Algorithm 25: Maze Project
Algorithm 26: Short Job First using Icomparer
Algorithm 27: Leetcode 554 Brick wall



Monday, July 24, 2017

Boggle - find words in matrix of letters

July 24, 2017

Plan to study the algorithm Boggle coding blog. The blog link is here written by Aviad Ezra.

There are a lot of thing for Julia to learn through those blog and code sample. Let us read words from Aviad Ezra together in the following:

Learn: Cracking the interview, solve all 189 questions.

Practice: Nothing beats mock interviews. It will boost your confidence and you’ll learn a ton from having someone watching you and listening to your explanations while you solve coding problems. You can pair with a friend or use one of the free peer-to-peer mock interviewing platforms. You don’t need to sacrifice your first interviews just to get hands-on practice.

Think fast: Developers that can think on their feet do much better in coding interviews. Practice in as many competitive programming sessions as you can.

Before you lost hope, keep in mind that there's a finite number of algorithms topics and only a handful of data structures that are used in the interviews.

Those words from  Aviad Ezra are so encouraging, Julia wrote her own blog about "Can mocking make difference?". First time she learns to work with people, share with people, learn from people on small things, like presenting her face in the centre through the video, ask good questions, give good hint, form a quick friendship etc.

In the following, Julia uses Leetcode 212 to help herself review Trie data structure and learn how to apply same algorithm as Boggle classified in Leetcode.



Leetcode 212 - word search II


Review Leetcode 212 last practice using Trie. The link is here.

It is so surprising that learning Trie and practice depth first search is most fun activities in the summer of 2017. Julia has to warm up the algorithm, play with one test case with Trie class, and also make the code more readable. Here is the warmup C# code using Trie data structure, recursive function calls. The solution is optimal and also pass online judge.

It is also a good idea to discuss why Trie is needed for better time complexity.

Brute force solution is to go over each word in the dictionary, and then try to find it in the matrix. The total number of search using DFS is m (words) * rows (matrix) * columns (matrix).

The brute force solution has timeout issue through Leetcode online judge. We like to review why the time complexity should be better.

Let us go over dictionary with 4 words, "aaa", "aaaa","aaab", "aaac". If we pre-process the dictionary and store all words in a Trie, and then we do not have to go over each words to search matrix. We only need to go over each element in matrix as start char in a word, search the trie to find match words using recursive function. The number of search using DFS is rows (matrix) * columns (matrix).

Second advantage related to the above 4 words ( "aaa", "aaaa","aaab", "aaac") is taking advantage of Trie data structure. The space complexity of Trie is better compared to hashset or hashtable. The same prefix "aaa" is only repeated once in the Trie.

This hard level algorithm applying Trie will be Julia's most favorite algorithm in the month of July 2017.

One of practice in 2017 is prefix neighbor on hackerrank, Julia asked the code review on stackexchange.com.


July 26, 2017

Trie against Hashset


Related to the test with a dictionary "aaa","aaaa","aaab","aaac","aaad", let us work together to talk about the difference.

For example, if the dictionary is saved in hashset, then go over each word in the dictionary, try to find word in matrix.
For example, "aaab", the first three letters has to be compared and they are the same first, then the last letter will be checked. Same will be applied to another 4 words. In total, the prefix "aaa" will be compared exactly 5 times in order to find those 5 words.

Can we do better? Just compare the prefix "aaa" once? Cetainly we can. We can save the words in a trie instead of hashset.

a
|
a
|
a
|\  \  \
| \  \  \
|  \  \  \
a  b  c  d



Trie efficiency talk 



It takes some time to get comfortable to design a Trie. So far, Julia has written a Trie implementation more than 4 times in C# last 3 years. Given the fact that she has worked on computer science more than 20 years, if she writes a algorithm every day, then she will write 60,000 algorithms. It is smart to focus on one simple thing, write code for algorithm and data structure, no matter life goes up and down, make it a hobby.

How to design a Trie so that the space complexity is minimum?
For example, the dictionary has the following words, "aaa","aaaa","aaaaa","aaaaaa".
How to store them in Trie efficiently?
a
|
a
|
a   word: "aaa"
|
a   word: "aaaa"
|
a   word: "aaaaa"
|
a   word: "aaaaaa"

The above diagram shows that those four words are saved in a Trie. How many char 'a' are saved in Trie, only 6, not 3 + 4 + 5 + 6 = 18 chars. Four words are saved along the trie nodes.

Every node can represent a word, it does not have to be a leaf node.

It is a smart decision to write down some test cases, so next time when Julia comes cross an algorithm, she can quickly relate to the test cases and figure out the advantage of using Trie.

Tuesday, June 13, 2017

Leetcode 212: Word Search II

June 13, 2017

Problem statement

Introduction



Trie is the kind of tree data structure and easy to save space with common prefix. Julia spent over 5 hours to work on one of trie algorithm and posted a code review on stackexchange.com called prefix neighbor. She went through the trie and learned that the trie can be in any form.

This time Julia had to relearn trie again. She had the weakness of data structure Trie, she could not figure out how to solve test case 36 and 37 two test cases timeout issue.

Code practice 


It is the hard level algorithm.

Julia worked on the Leetcode 212 word search.

Her first submission failed last 2 test cases from 36 - 37. Timeout issue. Julia did not know that she needs to use trie, she just used recursive function. The code is here.

Here is the C# code.

She studies the discussion written by a Googler - Yavinci, and wrote second practice. Still work on the code for more testing. Here is the C# code.

Julia continued to work on the trie and here is the C# code passing leetcode online judge.


Algorithm talk - learn Trie again



It is interesting to learn how data structure Trie to help solving timeout issues. For example, there are a lot of words like "aaaa", "aaab", "aaac", ...,"aaaz", Julia was so naive on June 13, 2017. She just goes over each word in the dictionary, and try to find each word using depth first search (DFS) recursive calls.

However the last 2 test case of 37 test cases time out. But Julia did not have idea how to solve it.

Julia needs to take a data structure coaching lesson again. so great to catch the opportunity.

As we can see, those words have same prefix "aaa", and the fourth char or last char is a to z. How to save the time to search, for example, if the path is the prefix of one word, then we need to continue to search.

Think about time complexity. My original solution (the C# code) is to go over each word, and then start to search board using DFS; so time complexity is related to how many words, each word is searched through board using DFS. If 26 words all starting from same prefix "aaa", then "aaa" will be searched in the board over 26 times.

The idea of using Trie, and then go over each element in the board, and then do DFS search against the Trie tree.

So preparation is the key, store all words to a prefix tree first.

Trie 


Plan to read Trie wiki article, review time complexity advantage of using Trie data strucutre.

A trie has a number of advantages over binary search tree. A trie can also be used to replace a hash table.

Topcoder using Trie - the article link is here.
Hackerearth tutorial about Trie - the article link is here.
Read 10 pages lecture notes about Trie - CMU lecture notes is here.

Sunday, July 9, 2017

Am I good programmer?

July 9, 2017

Introduction


It is exciting to spend 30 minutes to do some research at the night of Sunday. The topic Julia chose is "Am I a good programmer?". Julia likes to be very competitive hackerrank contest player, good at computer algorithm and data structure. But also Julia likes to be a leader, enjoy the journey by sharing her struggle, learning process of hard topic on algorithm, data structure. How does she advance herself as a software programmer, learning as a system designer, and she also likes to pick up other skills. Like good humour, strong and healthy physical body and strong mental toughness, and good sense of humour, master a sports - tennis.

Julia made a few choices, chose to work on Leetcode algorithms, work on the coding blog, work on code review, Leetcode discussion. 


It is hard work to reinvent myself as a software programmer. Julia spends last 3 months to meet people and conduct mocking interview, in her career as a full time programmer last 7 year, it is the first time she starts to learn how to work with a peer through 60 minutes time range. She wrote a blog about common mistakes in mocking.

Last weekend Julia spent more than three hours to watch the show on netflix called Quantico, the actress Priyanka has more than 17.9M followers on twitter. Julia likes to spend some time to read how the actress develops skills and build a good connection with peers. The actor Jake wiki page is here.

Coding, learning algorithm, reading and also mocking, Julia starts to get good habit to practice daily. But it is better to take Sunday off . Say no to algorithm and data structure, mocking interviews on Sunday, learn to relax more in the summer. Also Julia has to spend time to work on the sponsor application project.

Julia still calculates how much time she spends on the internet in the week days, she did waste a lot of hours. Instead she should plan better to work on more meaningful activities, like attending Sunday church service, get connected to friends and family, play more sports like tennis single matches, make life more fun and exciting.


Study topic 



It is the great experience to serve 8000 views last month. Most of time the blog serves Julia very well, she has chance to keep tracking of her progress on algorithm and data structure, and also keep her motivated and focus very well. So far there are over 150,000 views on the blog.

Over 10 years ago, Julia spent over 3 months in 2006 to study how to apply teaching job but she never got too far. She remembered that the bible verse teaching about seeds, how to grow the confidence. Seed and soil, Matthew 13 - The Parable of the sower.


Julia spent whole month in the city of Canada, so 25% traffic is from Canada. In other words, Julia serves 75% traffic for other people while she enjoys her own blog with 1700 views. 



By integrating Leetcode with mocking interview algorithm, Julia also learns to serve other people, help herself as well to learn better on algorithm and data structure. Here is the list of Leetcode algorithms last 3 month Julia worked on. Also 30% of peers were happy to connect Julia on linkedin, total count is 33. 

The mocking interview totally changes the view of Linkedin, for a long time, Julia found out that she does not have time to get connected to people face-to-face, work on something together. 


Let us look in LinkedIn statistics and figure out something here as well. 


Julia spent time on mocking interview last 3 months, 90 mocking takes 90 hours; And Julia worked on related Leetcode algorithms more than 30 hours. She added 33 new Linkedin connections, total 201 views, 15% traffic is related to the new connections. 26 found you via Who Viewed Your Profile, in other words, Julia did some study on linkedIn profiles, 10% traffic is related to the activities. 75% traffic of 150 views are random traffic, Julia could not control and make some influence on it. 

Last 3 months Julia did not spend a lot of hours on code review. Here is her profile:


Julia found her most favorite website to study and get great ideas for algorithm, and learn C# programming, for example, C# class SortedSet is good to start. . It is called Leetcode discussion board. Here is Julia's profile on Leetcode discussion. 
A few issues needs to be addressed, but Julia will find time to solve them. 


Leetcode algorithms


Last 90 days, Julia worked on 52 leetcode algorithms. Here are the list:

52 Leetcode algorithms 

8, 10, 18,  23, 33,,37,,39, 44, 45, 47, 48, 54, 55, 57, 69, 72, 76, 78, 79, 114, 121, 122, 123, 128, 140, 151, 153, 189, 212, 220, 239, 295, 300, 416, 459, 480, 516, 551, 572, 575, 582, 591, 605, 606, 609



Sunday, December 10, 2017

Code Review: Learn Trie from Leetcode 212

Dec. 10, 2017


Introduction


I posted a question on code review today, it is called Learn Trie from Leetcode 212. I got a comment to read patricia trie for space complexity, so I spent 30 minutes to read about it.


30 minutes reading


Here is one article I like to read, the link is Compressing Radix Tress Without Tears.


Saturday, July 21, 2018

What is the best way to learn the algorithm?

July 21, 2018

Introduction


It is very good research topic for my Saturday afternoon. I spent whole day to study inside my home office, I tried to push myself hard before I go out to play tennis and relax myself. What is the best way to learn the algorithm?

I did come cross the blog in April and like to review 98 algorithm videos prepared by facebook engineer called basketballwang. Here is the link.

I like to push myself to write as many as easy level algorithms this weekend. Here is report generated by Leetcode.com:

111/861/ solved, Easy 33, Medium 48, Hard 30


Preparation


I like to try to take an approach to work on easy level algorithms this time. I really like the easy level algorithm. I can quickly learn something and do not stress me out too often. The learning time is so much fun and I definitely enjoy the experience.

I also like to learn how to push myself to solve problems as well.


My experience


I do like the algorithm and data structure problem solving. I can tell the big difference through my performance. I do not know when I develop so much on the coding skills. People ask me a few times how long it takes you to develop the skills.

I certainly enjoy to write code for algorithms.

I do see my weakness. I have to build my skills through those Leetcode easy level algorithms. I like to the statistics showing that I have solved Easy 50 algorithms, and I have solved more than 120/ 861.

I created 10 blogs to prepare myself to watch 10 videos out of 95 algorithms prepare by a Facebook engineer this past April 2018. But I was too busy to watch any. Here is my blog link.


Learn to push myself hard


I will figure out ways to push myself hard. I am getting better on this way to train myself using Leetcode easy level algorithms. There are hundreds of easy level algorithm, and every time I submit online judge, I learn how to deal with the feedback and fix the problem right away.

Here is the code I wrote and submitted on Leetcode online judge this Saturday 7/21/2018 from 10:00 AM to 6:00 PM.



I wrote four algorithms, one dynamic programming called house robber, another one called unique paths II, and then I wrote one called Merge sorted array, and last one is called intersection of two arrays.

Here is my favorite icon to show how many problems I have solved up to 6:08 PM, 7/21/2018. I like to make training simple, solve 10 more easy level algorithm next.


Follow up 


July 26, 2018
Best way to learn the algorithm is to work on Leetcode easy level algorithm first. If I learn so many ways to solve easy level algorithms, it is so easy to use one of methods to solve a medium level or hard level algorithm.

If I can solve an easy level algorithm very well, it opens the door for a medium level or hard level algorithm.


Sept. 13, 2018

Leetcode 897 algorithms

Easy 265 / Medium 437 / Hard 195

May 9, 2019
Leetcode solved algorithms

Total: 1036

Easy 212 Medium 142 Hard 43

Monday, June 15, 2020

Leetcode discuss: Trie data structure showcase

Here is the link.

C# Trie showcase starting from 2018

C# Trie showcase practice starting from 2017
  1. Word Search II
    C# First practice using Trie in 2017
    C# Trie data structure DFS algorithm practice in June 2020
More practice:
139 word break I
I plan to write a solution using Trie to expedite the search of dictionary.
Tsinghua coach - my practice in 2018
Suggest a char based on prefix occurrence


Thursday, November 9, 2017

What is the third algorithm to ask code review?

Nov. 9, 2017

Introduction



It was 11:10 pm, and I spent over 30 minutes to go over the algorithm I practiced, and try to find a good one to ask code review.

Now it is 11:45 pm. The one I am reading now is leetcode 212 using trie data structure, the blog is here.

I came back from a break this September and asked two algorithms based on my mock interview practice. Today I like to find the third algorithm to ask code review.


Algorithm review

Trie 


It is also good warm up to review my favorite practice and share with the community.

Plan to study the algorithms of Trie from code review website, Trie implementation for left to right wildcard search, and another one: Trie (tree form) in Java

4 Sum



Wednesday, May 23, 2018

Being an interviewee: Suggest a char with maximum occurrence at the position with the given prefix

May 23, 2018

Introduction


It is my most favorite algorithm to practice with my coach. The algorithm is called to suggest a char with maximum occurrence at the position with the given prefix.

The coached asked me if I have Trie experience two days before my mock interview, so I spent some time to review Leetcode 212 and also my question on stackexchange.com.

The conversation of writing a Trie data structure was very interesting.


Coach: can you explain how you define the Trie?
Julia: It should be recursive structure, Children should have Node type as well.
Coach: Do you need to have a list of numbers for children?
Julia: No. It should be minimum. Every node just takes care of its own number.

In-between the mock interview, the coach asked me why you define the Trie this way, save "ABC" as a member of class definition. I just told the coach that I memorized the solution I reviewed recently. But actually we do not need to do that here. I felt much more relax after we work together more than 10 hours.

Trie algorithm


I learn how to work with the coach and write a solution in the mock interview. And also the coach asked me to test the code using the test case documented from line 93 to line 96, I found the bug on line 107, and delay increment of index variable until line 123.

Here is the transcript of the mock interview.

Follow up 


I wrote the C# code and tested it using a simple test case. Now it is 12:21 AM, I need to rush to go to bed since at tomorrow 8:00 AM I will have a mock interview.

10:00 PM mock interview as interviewer


I also ask the interviewee to work on the algorithm at 10:00 PM mock interview. The intervewee has more than eight years experience working in Silicon Valley to target for biggest software companies, and I helped him to write a Trie solution. What I did is to try to copy my coach, how he did to me. I asked the interviewee to work on the test case, show me the trie, and also give hint to use array for fixed size instead of using Dictionary.

Here is the C# code the interviewee wrote before I write my own C# solution.

Code review from my coach


I sent an email to ask the coach to review my code before I will have next mock interview. The coach offered me to send the code before mocking interview after our second mock interview, so he can prepare better for next mock interview. We can squeeze in more activities in the mock interview together. My coach is super talent programmer and I like his working attitude.

"I think that it is definitely no problem at all. Let us meet Friday morning.

I just like to send you the code I wrote for suggest char based on prefix.

Here is the link."

May 25, 2018
8:00 AM

My coach told me that one thing is not correct. The iterate variable may be null pointer. I need to add null pointer checking on line 152.

Saturday, September 22, 2018

My fourth interview on interviewing.io

Sept. 22, 2018

Introduction


It was my 9:00 PM mock interview, and it was my fourth interview as an interviewee. I had chance to work with the interviewer, and I answered the first three algorithms and explained the ideas in the first 12 minutes, and then moved on the fourth algorithm which is the hard level Leetcode 212 Trie. I explained the idea how to solve the algorithm, and wrote the code until we reached 45 minutes mark. We chat about 15 minutes about practicing and learning.

I had 10:00 PM mock interview as an interviewer, and I did not explain to the interviewer of 9:00 PM until 10:01 PM. I rushed to say goodbye and then started my 10:02 mock interview.

My performance


Group anagrams

Minimum meeting rooms



Find words in the dictionary


My feedback as an interviewee


Would you want to work with this person? *

Yes

How excited would you be to work with them? 


Where do I sign?!!?

How good were the questions? 


Really useful/awesome!

How helpful was your interviewer in guiding you to the solution(s)? 


Awesome!

Help your interviewer get better! 




Interviewer's feedback


Do you want to advance this person to the next round (e.g. onsite)? *

No

How were their technical skills? 

starstarstarstar
Could use improvement

How was their problem solving ability? 

starstarstarstar
Could use improvement

What about their communication ability? 

starstarstarstar
Amazing!

Help your interviewee get better! 

Wednesday, July 3, 2019

212. Word Search II

I was shy and chose not to share my C# practice on Leetcode.com from 2017 January to Jaunary 2018. Today I shared all my three submissions on Leetcode.com.

Here are the links:

1. First practice is here.
2. Second practice is C# practice using Trie and good explanation in detail.
3. Third practice is C# Using Trie with a case study practice in January 2018.

Sunday, October 25, 2020

Leetcode discuss: 1631. Path With Minimum Effort

Here is the link on youtube.com. 



Here is my Leetcode discuss post.

First practice - C# copy idea and copy code to learn quickly

Oct. 25, 2020
Introduction
It is the third algorithm in weekly contest 212. I started the contest late and only had 10 minutes left, I thought about the problem and it was hard. I could not find a working idea.

After the contest
I just quickly went over the discussion post, and then I like to study the code and then figure out the following:

  1. Start from top left node in the matrix, define C# Tuple<int, int,int>(int Height, int row, int col);
  2. Try to start from top left node to visit all nodes in the matrix, but choose the order to get minimum distance. How to do that? Design a minimum heap.
  3. Define a minimum heap with distance, and always remove the minimum node from the heap, and then visit it's unvisited neighbors, and add all those neighbors to the heap.
  4. Make sure that visit all nodes in the order based on minimum distance until bottom right node is reached.
  5. Define a node with distance based on consideration of previous node's distance in minimum heap process and current one.

Case study
I think that the code is pretty standard minimum heap practice once I understand the idea and learn how to reason it.

I need to look into C# SortedSet default comparer for this Tuple<int, int, int>. It is surprising that the code can be simplified using short hand expression, and no need to write any code related to IComparer as well. I did look up Google.

It is much better to work on a small case study, then I can quickly understand the algorithm and how to design it next time.

Example:
Matrix
1, 2, 3
3, 8, 2
5, 3, 5
Using A, B, C, D, E to mark those first five nodes in matrix.
1A, 2B, 3C
3D, 8E, 2
5, 3, 5
Add A node in matrix into minimum heap, (0,0,0), remove minimum one in the heap, and then visit A's neighbor nodes B and D, and then add B and D into minimum heap.
Next step is to remove minimum node in the heap, which is B. The distance is 1, and add C and E into the heap.

Step by step
Let me work on a more simple example,
Example:
Matrix
1, 2
3, 8
Add A, B, C, D marks to simplify the explanation.
1A, 2B
3C, 8D
1A is added to minimum heap, the minimum effort is 0;
remove 1A from minimum heap, and visit two neighbors, 2B and 3C.
1A -> 2B has minimum effort 1, and 1A to 3C has minimum effort 2.

Add 2B and 3C to minimum heap. The smallest one is 2B.

Next is to remove 3B from minimum heap, visit 2B's neighbor 8D, so 8D has minimum effort 6. Add (6, 1, 1) to minimum heap.

Next is to remove 3C from minimum heap, visit 3C's neighbor 8D, so 8D has minimum effort 5. Add (5, 1, 1) to minimum heap.

The tip is to mark visit only after the node is popped from minimum heap. In our simple example case, 8D has chance to be added into minimum heap more than once, first one is with height 6, second one is with height 5.

Since minimum heap is sorted, the path from 1A->3C->8D is removed from minimum heap first before 1A->2B->8D, the answer is 5 not 6.

In summary, the first tip is enforce order using minimum heap, and the second tip is to mark visit after the node is removed from minimum heap, so one node 8D has two chance to be considered and added to minimum heap. It is kind of clever. But it took me over 30 minutes to figure out, I had to debug the code using Visual studo first, and then figure out step by step.

Go over again, the minimum heap step by step:

  1. 1A, (0, 0, 0)
  2. remove 1A from heap, add 2B and 3C, sort them.
    (1, 0, 1)
    (2, 1, 0)
  3. remove 2B from minimum heap, add 8D into minimum heap.
    (2, 1, 0)
    (6, 1, 1)
  4. remove 3C from minimum heap, add 8D into minimum heap.
    (6, 1, 1)
    (5, 1, 1)
    sort them
    (5, 1, 1)
    (6, 1, 1)
    Remove 8D from minimum heap, which is bottom right, minimum effort is 5, not 6. The path is from 1A -> 3C -> 8D.

I do believe if I can read this short case study, then I can write the code in the contest or phone screen in 10 minutes. But I have to go over step by step to understand competition of two 8D entries in minimum heap in order to get minimum effort.

public class Solution {
        // (0,1),(1,0),(0,-1), (-1,0) four directions, simplified version
        private int[] directions = new int[] { 0, 1, 0, -1, 0 };
    
        /// Oct. 25, 2020
        /// study code: 
        public int MinimumEffortPath(int[][] heights)
        {
            int r = heights.Length;
            int c = heights[0].Length;
            bool[,] visited = new bool[r,c];
            
            // declare Tuple data type
            // https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/types
            // new Tuple<int,int,int>( int H, int X, int Y) -> short hand -> (int H, int X, int Y)
            // default comparer ? 
            var sorted = new SortedSet<(int H, int X, int Y)>();
            
            sorted.Add((0, 0, 0)); 
            while (sorted.Count > 0)
            {
                // find smallest one in Height, if the same, then compare X, then compare Y
                // ask why? What is strategy? Find smallest one - greedy 
                // 
                var cur = sorted.Min;
                
                if (cur.X == r - 1 && cur.Y == c - 1)
                {
                    return cur.H;
                }
                
                visited[cur.X, cur.Y] = true;
                
                // Look up C# SortedSet source code - Remove API
                // very complicated - red black tree - find node and remove node
                // https://referencesource.microsoft.com/#system/compmod/system/collections/generic/sortedset.cs
                sorted.Remove(cur);
                
                for (int d = 0; d < 4; d++)
                {
                    int nx = cur.X + directions[d];
                    int ny = cur.Y + directions[d + 1];
                    
                    if(nx < 0 || nx == r || ny < 0 || ny == c || visited[nx,ny]) 
                    {
						continue;
                    }
                   
                    // all nodes in smallest path - smallest distance should be maximum one
                    var next = Math.Max(cur.H, Math.Abs(heights[cur.X][cur.Y] - heights[nx][ny]));
                    
                    sorted.Add((next,nx,ny));
                }
            }

            return 0;
        }
}

After mock interview
10/25/2020 3:58 PM 

I could not make it work in my mock interview as an interviewer, then I debugged the code using visual studio, and learned the detail the competition case in minimum heap. 

I recorded another video.