Showing posts sorted by date for query divide and conquer. Sort by relevance Show all posts
Showing posts sorted by date for query divide and conquer. Sort by relevance Show all posts

Tuesday, July 19, 2022

Leetcode discuss: 84. Largest Rectangle in Histogram

July 19, 2022

Here is the link. 


C# | Quick learner | Optimal time complexity solution provided

Dec. 3, 2020
I work on five solutions and I like to share the solution using stack with optimal time complexity O(N^2). Also, I add brute force solution as solution 2, which may not be helpful for any interview preparation, O(N^3).

All solutions in series:

  1. Brute force
  2. Better brute force
  3. Divide and conquer
  4. Better divide and conquer
  5. Using stack

Solution 1: Using stack | Time complexity: O(N)

Example | Case study | Ask good questions
It is a hard level algorithm. Every one should think about using stack to reach optimal time complexity O(N). But how to maintain the stack and keep ascending stack to meet calculation need. I like to contribute some good thoughts so that you and I both learn something.

image
How to calculate the largest histogram area - 10, what is in stack when iteration to index = 4, value 2, I believe that maximum area will calculate including 6 - as one standalone, and then two - 5 and 6, and then 6 should be popped from stack, 6 should be popped from 5, since 5 and 6 will no longer be needed in any calculation for possible bigger area any more.

One thing to argue is that the stack should always keep the minimum value in the stack before it reaches the last one in the stack. That one is possible candidate for largest histogram area, using minimum value multiplys the length of the array.

Calculation when index = 4, value 2

  1. Pop 6 since 6 > 2 - calculate area 6 -> 6, compare to maximum area so far
  2. Pop 5 since 5 > 2 - calculate area from 5, 6 -> 10, compare to maximum area so far
  3. Compare 1 vs 2, leave 1 in stack, no calculation, push 2 into the stack, {1, 2}. 

Think about the above steps, see if anything is wrong or missing anything for possible largest histogram area.

Go back and forth to warm up the algorithm design using the above histogram, ask more questions. Using debugger, and then make sure that the argument is true or false.

Requirement analysis:
I reviewed a few videos on youtube.com related to this algorithm. I do think that the missing part in those video is about how to analyze starting from brute force, and come out requirement for optimal solution:

  1. Need to find minimum value in the array, for width of span of whole array.
  2. Need to find maximum value in the array, for only one number area;
  3. Need to argue that ascending order numbers, we can skip multiple areas for one number, two numbers, three numbers etc. to one of them, as long as we count the numbers from highest to smaller ones in consecutive orders. (This is interesting math problem, we can prove that it is true.)
  4. Next extract the design of data structure of ascending stack.
  5. We need to make sure that for all width from 1 to n, n is the length of the array, we need to select at least one of them, maximum one should be included.
  6. More on step 5, relax on this requirement, we can find multiple time as long as we maintain the ascending stack, and pop up those numbers bigger than current number.
public class Solution {
    public int LargestRectangleArea(int[] height) {
            var stack = new Stack<int>();

            var index = 0;
            var largestArea = 0;

            int length = height.Length; // 6

            while (index < length) // true; index = 1; index = 2;
            { 
                //     stack empty            going upward
                if (stack.Count == 0 || height[stack.Peek()] < height[index]) // index = 1, false;
                {
                    stack.Push(index++); // 0, index = 1;
                }
                else
                {
                    // going downward and then pop stack, calculate rectangle.
                    popStackAndCalculate(ref largestArea, stack, height, index);
                }
            }

            while (stack.Count > 0)
            {
                popStackAndCalculate(ref largestArea, stack, height, length);
            }

            return largestArea;
        }

        /// <summary>
        /// downward and then pop stack to calculate the rectangle
        /// </summary>
        /// <param name="largestArea"></param>
        /// <param name="stack"></param>
        /// <param name="height"></param>
        private static void popStackAndCalculate(ref int largestArea, Stack<int> stack, int[] height, int rightIndex)
        {
            int length = height.Length; // 6

            int lastHeight = height[stack.Pop()]; // 2
            int width = stack.Count == 0 ? rightIndex : rightIndex - stack.Peek() - 1; // 1

            largestArea = Math.Max(largestArea, lastHeight * width); // 2 * 1
        }
}

Solution 2: Brute force solution | Naive approach
I like to quickly share the brute force solution. This is a good exercise to review basics of for loop and make sure that calculation is correct first.

Five series - C# - Brute force - TLE - Time O(N^3)

Consider every possible pair of bars, and find the area of the rectangle formed between them using the height of the shortest bar lying between them as the height and the spacing between them as the width of the rectangle. We can thus, find the required rectangle with the maximum area.

public class Solution {
    /// <summary>
        /// brute force solution
        /// Time complexity: O(N^3)
        /// start and end position - all possible pairs - O(N^2)
        /// Find minimum height in given range - O(N)
        /// Total time complexity is O(N^3). 
        /// </summary>
        /// <param name="heights"></param>
        /// <returns></returns>
        public int LargestRectangleArea(int[] heights)
        {
            var length = heights.Length; 
            int maxarea = 0;

            for (int start = 0; start < length; start++)
            {
                for (int end = start; end < length; end++)
                {
                    var minHeight = Int32.MaxValue;

                    for (int k = start; k <= end; k++)
                    {
                        minHeight = Math.Min(minHeight, heights[k]);
                    }

                    maxarea = Math.Max(maxarea, minHeight * (end - start + 1));
                }
            }

            return maxarea;
        }
}

Wednesday, March 9, 2022

FB, MSFT interview: Case study

Here is the article. 

Hello everyone, I got multiple good questions asked in my interview experience with Microsoft and one of the requests was to provide a summary of my preparation journey. There was a time (couple of years back) when writing a iterative pre-order traversal of binary tree, or even a basic stairs dynamic problem used to be a daunting task for me. Then I accepted my current situation and came up with a plan to improve my coding skills and system design skills which I will share with you along with my learnings during this journey.

Micorsoft Interview Experience (just in case you missed it) :
https://leetcode.com/discuss/interview-experience/1260613/microsoft-engineering-manager-hyderabad-may-2021-offer/969476

Before I start, I would like to thank the entire LeetCode Community for all the help and encouragement over the last few years for the interview preparation.

Familiarising with basic algorithms and data structures

Coding Book I followed - The book which was highly recommended to me was Cormen and I quickly glanced thorugh few chapters and I realised though this is an excellent text - it is not suited for improving my coding practices. I was looking for some book which would explain the concept and also have a working code in some languages (preferably C or Java) and after exploring around 8-10 books I narrowed down to the following:

  1. Algorithms (4e) - Robert Sedgewick
  2. The Algorithm Design Manual - Skienna
  3. Elements of Programming Interview - Adnan Aziz

If you want to know all the books that I explored then let me know in the comments. I have a small library where those books are still lying peacefully :D.

I learned the basic implementation of Heap, Trie, Graphs and their traversals, Dynamic Programming and its basics, Stack and Queues etc. from the first book. I also referred second book time to time. Once I had learnt all the basic implementation of all the data structures and classic algorithms next step was to solve some problems.

And for the problem solving I explored the following books:

  1. Elements of Programming Interview (Java edition) - excellent choice as the number and quality of problems is good and explanation is also very good.
  2. Cracking the coding interview - descent book but the quality of problems is not great IMO. It may be an excellent book few years back but now its just okay.
  3. DS and Algo made easy - poorly written book with some random code samples collected together without any continuity and explanation is almost non-existent. Please avoid this book.

Coding Platform I followed - I explored hcker-rank, hcker-earth, gek-for-geks(G4G) and leetcode. My experience is that first two platforms will have lengthy description of the problem before coming to the real problem and that was frustrating for me because of the time I was wasting in reading that huge description of the problem. The G4G was having too many problems and majority of them are not well defined, solutions not well explained and absolutely no categorization of the problems and solutions - same problem repeated multiple times with different solutions and zero organization. So I did not use any of those platforms any longer.

I was quite impressed with the quality of the problems in leetcode. Also it was also highly recommended by some of my friends in Google/FB/MS and hence I followed only one platform and that is leetcode. The first thing after that I did was to get subscription of premium as that is highly useful. You can have five sessions under one subscription.

========================== Fun Begins Now ================================

Phase 1 - Baby Steps
In the beginning, I focused on easy questions to gain confidence and get some consistency. Once I overcame the friction of doing questions, I moved onto the medium and hard questions. I followed 60-30-10 rule where 60 percent of the problems I solved were easy, 30 percent were medium and only 10 percent were hard.

How did I select those problems? The answer is I divided the problems into multiple topics and for each topic I targeted the problems which were asked in companies (locked problems which can be seen if you have premium) and the commonly asked problems in interviews (as discussed on leetcode community). In phase one I targeted the following topics:

  1. Sliding Window
  2. Two Pointers
  3. Array problems (Search, Sort etc) - mastered Binary Search also
  4. Tree based problems (Binary Tree and Binary Search Tree only)
  5. Stack and Queue based problems
  6. Heap problems

I also referred to a link (cannot locate it) for dividing problems on basis of topic (similar to the below link):
https://leetcode.com/discuss/career/448024/Topic-wise-problems-for-Beginners

Note: Whatever problems I solved I kept all my learning and solutions in a word document which I could refer whenever and wherever I want. This is very important in case you want to revise any concept or a problem in future.

You will get an urge to see the solution during early phase esp - but do not look at the solution until and unless you are sure that you have tried all your ideas. If you have tried all then look at the solution, try to see what did you miss and do keep that in mind. Also even if you have solved the problem and it is accepted - do check the discuss tab and look for top 5 or top 10 highly voted solutions. I have learnt a lot from them.

Phase 2 - Trying to Stand up
In this phase I targeted the topics which were slightly difficult to grasp:

  1. Dynamic Programming
  2. Backtracking
  3. Divide-And-Conquer
  4. Graph problems

I took the help of tags here e.g. for graphs we can use the link: https://leetcode.com/tag/graph/ and then I sorted the problems on the basis of frequency and started targetting the most frequent problems (imo this is a premium feature). I spend a lot of time in understanding the underlying concept of graph traversals, how they relate to tree traversal e.g. similarity in BFS of graph and level order traversal of tree, how and why we use queue for BFS, how and when we can use stack in graph traversal, topological sort, pattern of backtracking - a result container which would store the value from temp, conditional return of temp, exploring paths, and backtracking by removing last item in temp etc. I divised some of my own patterns for backtracking and other areas and then I tried to reuse them into different problems.

Phase 3 - Trying to Run Now
In this phase I tried to solve all the locked problems (asked in companies), also mastered many patterns till now so used to revise them timely, also checked out top questions asked in leading companies like Microsoft, Facebook, Google etc. and tried to solve them. I focussed on some tricky topics:

  1. Intervals based problems
  2. Segment/Fenwick Tree
  3. Union Find (Connected Components)
  4. Hard Miscellaneous problems

I realized though I could solve easy problems most of the times and medium problems some times, I was still struggling with hard problems a lot. Some problems never crossed my mind even after spending 5-8 hours and that was hurting me a lot. So I changed my stratgey to focus on the problem for 20-30 minutes and if I could not make progress I will check the solution (and also the discuss tabs for most voted solutions) and will try to understand the solution and then keep the learning in my notes - which I would revise time to time.

It is very difficult to get time for coding practices esp when you are working so I used to take 30-40 minutes in morning where I will read about a problem, will brain storm to find the solution, used to discuss sometimes with my like minded peers, and will see the solution if I eventually give up. I used to address problems from diverse topics so that I wont loose the interest and also it is more effective stragetgy imo.

Try to solve a problem using multiple concepts
I used to try solving a problem using multiple ways and then try to compare complexity and other aspects.

Try to figure out if a problem can be mapped to a more commonly asked problem and use that solution.
This has been a good learning where I learnt how to solve a classic problem and then during my journey realised that multiple problems can be mapeed to same problem. For example 960. Delete Columns to Make Sorted III and 354. Russian Doll Envelopes are very similar to the problem 300. Longest Increasing Subsequence and solution for that can be reused to solve other two problems as well.

Do not spend too much time on a single problem
I have solved 300+ problems and this is what I learnt. Always try 10-15 minutes in a problem to find the pattern e.g. check if it needs exhaustive search (may be we can use BFS), or it needs backtrack, or it can be solved by DP after we have explored and sovled for multiple given inputs etc.
If the pattern is too obvious then sometimes I skip the problem to focus on other problems.

Keep eye on locked and tricky problems
Always look out for problems which have some tricks underlying them - IMO they have high chance of being asked in upcoming interviews.
I recommend to take the leetcode premium subscription then you can also unlock the locked problems and articles. You can have five active session in one subscription and can share with friends to share cost.

Phase 4 - System Design
Honestly I have been designing systems in my current job profile so I did not spend too much time on this. But I still found the following materials useful for my preparation:

  1. Course Gr**** the System Design Course from Ed**** (Sorry for the * as LeetCode does not allow me to write those words in the post. I hope you can guess the course) very useful. This course is highly recommended and is worth it.
  2. Famous System Design Primer on Github
  3. Articles on high scalability - Highscalability.com
  4. Posts tagged under System Design on LeetCode Discuss - https://leetcode.com/discuss/interview-question?currentPage=1&orderBy=most_votes&query=&tag=system-design

There are too many youtube channels having system design videos - imo they are mostly useless as they are not comprehensive and some of them are even plain wrong about the design idea. I suggest to follow official videos from various companies, infoQ videos, Facebook Developers videos etc. They are really useful to get that final feather in your hat!

I would like to conclude this with some interesting links:
https://leetcode.com/discuss/career/449135/how-to-effectively-use-leetcode-to-prepare-for-interviews
https://leetcode.com/discuss/general-discussion/665604/Important-and-Useful-links-from-all-over-the-LeetCode
https://leetcode.com/discuss/general-discussion/494279/comprehensive-data-structure-and-algorithm-study-guide
https://leetcode.com/discuss/general-discussion/459286/Best-Posts-of-2019
https://leetcode.com/discuss/general-discussion/522705/1000-leetcode-problems-within-a-year
https://leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns/544912

=============== Books I explored ================
Some of you are showing interest in the books I explored so I have listed them below and rating is as per my opinion(rated out of 5):

Algorithms Prep
Algorithms 4e(4.5) - excellent book for algorithms and DS
Algorithm design manual (4) - very good
Cormen (4) - good text book but voluminous and more for academic and research
DS and Algo made easy (2) - poor book so avoid it. Its more of a collection of random code samples without any continuity. Too many coding errors and poor explanation.
Algo in a nutshell (2.5) - descent for overview of algo
DS by Lafore (2) - text book kind of not much useful
DS by Weiss (3) - text book

Problem Solving
Element of Programming Interview (4.5) - excellent book for coding prep
Cracking the coding (3) - descent book for coding prep
Programming Interviews exposed (3) - okayish book

Coding Practices
Clean Code (4) - excellent book
Clean Coder (3.5)
Programming Pearls (4) - just covered half of the book only

Architecture
Clean Architecture (3.5)
Design Patterns by Gamma (4) - classical text
Patterns of Enterprise app architecture (4) - great book by Fowler

System Design
Designing Data-Intensive Applications (4) - great book but takes time to cover everything
Gr***ng the system design (4.5) - excellent choice

githubmicrosoft

Algorithms to study: FB | Google | Amazon | More | 2020 New graduate looking for FANG jobs

March 9, 2022

Here is the link.

Offers from Google L4 | Facebook E3 | Microsoft L60 | Amazon SDE1 (Experience)

Last Edit: April 1, 2020 4:48 AM

42.3K VIEWS

I would like to share my experience interviewing with Google, Facebook, Microsoft, Apple. I had a return offer from Amazon (SDE1). In the last 2 months, I took 6 phone screen, 4 onsites and got offers from Google (L4), Facebook (E3), Microsoft (L60). The TC information is at the end. I am also including my internship interview experience with Amazon.

I will try to add the equivalent leetcode questions (as many as I can remember).
Hope this will be helpful.

Profile:
MS in computer science (graduating in May 2020)
YOE : 2 before masters
Others: 1 internship at Amazon
Leetcode : 754 (E : 177, M : 451, H : 126)

Google | SDE L4 | Mountain View | March 2020 | (Accepted)

Application:
Contacted by recruiter. The position was for people with at least 2 YOE. The level will be decided by interview performance.

phone screen (45 min):
1 easy (string) , 1 hard (binary search, divide conquer) , 1 medium (string)
All 3 questions were LC questions, can be found in google's list in LC.
I felt the focus was more on basic understanding and approach towards the problem (rather than optimal solution). Bugs, incorrect syntax is totally fine as long as you can recognise them and fix it. One small note, practising coding on Google Doc can be a make or break factor. You don't want to get caught balancing braces during a LC hard.

virtual onsite:
4 technical rounds (45 min each), 1 behavioral round (45 min).
technical round 1 : 1 medium (linked list, recursion, multiple followups)
technical round 2 : 1 medium (string), 1 hard (graph)
technical round 3: 1 medium (Queue, follow-up on concurrency), 1 hard (binary search tree)
technical round 4: 1 easy (string), 1 hard (ad-hoc, minimax)
behavioral: Standard Googlyness questions (can be found online)

All questions were exact or slight variation of LC questions, more specifically from Google's list. Focus was more on optimal solution.

Leetode equvalent questions

  1. median of two sorted array
  2. Group Shifted Strings
  3. Flatten a Multilevel Doubly Linked List
  4. Redundant connection II
  5. Bulls and Cows
  6. Guess the word
  7. Recover Binary Search Tree

Decision Process:
Google has a lengthy process following onsite: hiring committee approval, team matching, executive committee approval. The time required to complete this steps depends on recruiter, other deadlines, interview performance. Mine was completed in 10 days (onsite to receiving offer letter).
For compensation negotiation, levels.fyi is very helpful. It's always best to go to them asking for way more than you expect. They generally do not take that as a negative.

Overall experience was awesome.

Facebook | SDE E3 | Mountain View | March 2020 | (Offered)

Application:
Applied for new grad position. Standrad new grad application.

Phone Screen:
1 medium (string, followup: Dynamic programming)
1 medium(array, hashmap, followup : array, hashmap)
All questions were LC questions, can be found in facebook's list. The focus was on correctness, finding optimal solution.

Virtual Onsite
2 technical rounds, 1 behavioral + technical round
Technical round 1: 1 medium (binary search tree), 1 hard (DFS)
Technical round 2: 1 medium(string, not LC), 1 medium(backtracking, multiple followup: backtracking)
Technical + behavioral round: Standard facebook behavioral questions, 1 medium (not LC, backtracking, DP question)

All but 2 questions can be found in facebook's list. There was multiple followup in all questions. My last round did not go well (partly because of connection issues, and partly because I messed up).

Leetcode equivalent questions

  1. Binary Tree Maximum Path Sum
  2. Combination I & II
  3. Valid Palindrome II & III
  4. Subarray Sum Equals K
  5. Product of Array Except Self
  6. Next Permutation

decision process
It took them around 7 business days to make decision and another 2 days for paperwork.

Overall experience was great.

Microsoft | L60 | Redmond | March 2020 (Offered)

Application:
Contacted manager over linkedIn. This was a domain specific research SDE role and did not follow the standard new grad process. Manager worked with recruiter to setup everything.

Phone screen
1 medium (BFS).
Discussion on past project, experience and domain specific topics.

Onsite
5 technical rounds. Focus was on coding, domain knowledge, system design
Technical 1 : discussion on past publication, project, domain knowledge. No coding questions.
Technical 2 : 1 hard (Trie, BFS), 1 hard (string). 1 system design. domain specific case based questions.
Technical 3 : some behavioral, past experience, research related questions. case based questions
Technical 4: 1 hard (array), 1 medium(BFS).
Technical 5: Past experience, research related questions, case based questions.

All coding questions can be found in Microsoft's list in LC. System design question a standrad question found in Grkking the System design interview.
The domain specific questions were difficult and lot more focused on how handle scale.

Leetcode equivalent questions

  1. Trapping Rain Water
  2. Regular expression matching
  3. Word search II
  4. Maximum Width of Binary Tree
  5. Shortest Path in Binary Matrix

Decision Process
They took 10 days to make a decision and sending an offer. This is strictly my personal opinion, but the negotiation process was not a great experience (lowballing with level, compensation, asking/hinting repetitively to sign).
Overall experience, mixed. (Team/engineers: great, recruiting process: not so much)

Apple | ML Engineer | Seattle | March 2020 (Passed)

Passed phone screens, Onsite was scheduled. But I had to cancel it.

Application
Contacted Manager over linkedIn.

Phone screen 1
1 medium (string), 1 medium (BFS). one ML case based question.
The coding questions can be found in Leetcode's top 100 questions.

Phone screen 2
This was focused around ML, no coding questions. ML questions were difficult and the interviewer went into details of each concept. Discussion around past experience, project, publication.

After 2 phone screen and another call with manager, they decided to schedule a onsite.
The overall experience was very very bad. Each phone screen was followed by a prolonged silence from recruiter. Because of that it took nearly 3.5 months to just complete 2 phone screens. Which is just ridiculous. I would have preferred to get rejected early on rather than continuing with this mess for so long.

I also, interviewed and got rejected from these companies/roles:

  1. Facebook | Operation research scientist | Onsite reject
  2. Stripe | new grad | Onsite reject
  3. Bloomberg | new grad | Onsite reject

Stripe | new grad | Bay Area | October 2019 | Rejected
Application:
Applied through career page with referral.

Phone Screen:
1 extremely easy question related to custom sorting.

Onsite
3 Technical rounds, 1 behavioral round
Technical round 1 (Integration interview) : Use an HTTP library to implement some HTTP request testing. Clone a Git repo. It will contain couple of JSON files with HTTP request information, query information and expected response. Design the request and response functionality and check correctness of your implementation. I messed up in this round.
Behavioral round: Questions on past experience, projects, future goals. Standard behavioral questions.
Technical round 2 (Coding interview) : 1 easy question (similar to optimal account balancing, if you are not asked to do it optimally, i.e. the total number for transaction need not be minimum. Followup : optimal account balancing)
Technical round 3 (Bug squashing) : Clone a Git repo. It will have two/three bugs. You have to fix them. I fixed one and identified the source of the second bug but couldn't fix it.

Stripe is known for their unique interview process. I knew about the rounds and what kind question will be there, but still they caught me off guard. It's because there is no way to practice the integration and bug squash interview. The only weakness in their process is they don't have too many different questions and have limited number of tricks (but damn, they were good).

Amazon | SDE Intern | Seattle | March 2019 | Accepted
Application:
Carrer page with referral.

Online assessment:
Amazon sends 2 online assessments (OA) for internship. One OA includes 2 coding questions and another OA includes 6/7 debugging questions. To my knowledge, people solving more 4 debugging questions and 2 coding questions are safe.

Phone screen:
This is the final round for Amazon SDE intern role. Usually 1/2 questions. I was asked:
Number of islands
LRU cache

Decision Process:
I got result within 1 day. Generally, Amazon has a 5 business day response policy.

Interview process was pretty streamlined.
Amazon does not have the greatest recruiting team and it takes a while to get a response. Probably because they hire so many SDEs. Also, you generally don't have any control on team selection or project.

Preparation
I would love to share more of my experience and process. But, there is a lot of great preparation/experience posts on Leetcode, reddit and more importantly, I am too lazy to write. But, here's something I understood in this process.

  1. Preparation is very subjective. Posts/guidelines are often not very helpful and unintentionally misleading. (yes, I see the irony here). If you are new to interviewing, it would be best to assume the first 2-3 interview you give will go horrendously bad (true story). But, that experience will allow you to finetune your process.

  2. Most (or atleast FAANG) companies will ask questions from Leetcode or slight modification of a leetcode question( > 90% in my case). The only way to mitigate risk is to increase the number of question you know or have solved before. It's better to solve 800 LC questions than to trust your problem solving skill over phone in a 45 minutes window or in a cold conference room with a bunch of strangers staring at you. Company specific lists are a better option. Company specific lists can be found in section 'Companies' in Problem page (if you can afford leetcode premium, it's worth it).

  3. Praticing interviewing over phone, virtual is important. So, something like Prmp can be very helpful. (Prmp offers free mocks). For onsite, if you have the luxury you can apply to 1/2 companies that you have no intention of joining or you know you won't get. This gave me a chance to adjust with travel, interviewing continuously for 3-4 hours (Note: May be considered unprofessional)

  4. In most cases, luck is a make or break factor, your skill may not matter. In a FAANG internship interview, one guy was asked a single question : "Two sum", another guy was asked "AVL tree". This kind of messed up things happen all the time. I am pretty sure, if I am interviewed again I may or may not pass all the interviews. I just got lucky. The only way to deal with that is same as point 2.

  5. If you need to use different languages for different interviews (in my case, ML interviews expected python and I prefer C++ for SDE interview) dedicate time to context switching. This might cause issues if you are not very comfortable with continous context switch.

TC information
TC includes base, stock (first year), sign-on bonus, performance bonus
Google L4 (MTV) : base 155K, TC : 325K
Facebook E3 (MTV): base 123K, TC 240K
Microsoft L60 (Redmond) : base 118K, TC 210K
Amazon L4 (Seattle): base 112K, TC 152K

googlefacebook offermicrosoft


March 19, 2022 - I like to take some time to prepare my own notes. 

My notes - I like to review those algorithms quickly:

  1. median of two sorted array
  2. Group Shifted Strings
  3. Flatten a Multilevel Doubly Linked List
  4. Redundant connection II
  5. Bulls and Cows
  6. Guess the word
  7. Recover Binary Search Tree
  1. Binary Tree Maximum Path Sum
  2. Combination I & II
  3. Valid Palindrome II & III
  4. Subarray Sum Equals K
  5. Product of Array Except Self
  6. Next Permutation
  1. Trapping Rain Water
  2. Regular expression matching
  3. Word search II
  4. Maximum Width of Binary Tree
  5. Shortest Path in Binary Matrix
Create a public list on Leetcode.com using my account. I did like to review and code carefully the algorithm called Recover binary search tree, Leetcode 99. 

Tuesday, March 8, 2022

30 hard level algorithms: google - Leetcode premium

 

30 hard level algorithms: google - Leetcode premium

 Dec. 7, 2020

Introduction

It is a tough project to work on. I am planning to go over the following 30 hard level algorithms provided by Leetcode premium. 

30 hard level algorithms

I like to go over those 30 hard level algorithms

  1. 727 Minimum windows subsequence - DP, sliding window
  2. 715 Range Module, Segment tree, ordered map
  3. 552 Student attendance record II, DP
  4. 465 Optimal account balancing 
  5. 1499 Max value of equation, Array, sliding window
  6. 753 Cracking the safe, math, DFS
  7. 1231 Divide Chocolate, Binary search, greedy
  8. 308 Range sum query 2D - Mutable, Binary indexed tree, segment tree
  9. 1293 Shortest path in a grid with obstacles elimination
  10. 1444 Number of ways of cutting a pizza, DP
  11. 527 Word abbreviation, string, Sort
  12. 1240 Tiling a rectangle with the fewest squares, DP, backtracking
  13. 315 Count of smaller numbers after self, Binary search, Divide and conquer, Sort, binary indexed tree, segment tree
  14. 460 LFU cache, design
  15. 1406 Stone game III
  16. 248 Strobogrammatic Number III
  17. 1610 Maximum number of visible points, Two pointers, Geometry
  18. 335 Self crossing, Math
  19. 420 Strong password checker
  20. 1345 Jump Game IV
  21. 679 24 Game
  22. 642 Design search autocomplete system
  23. 1377 Frog position after T seconds 
  24. 818 Race car
  25. 1255 Maximum score words formed by letters, bit manipulation
  26. 174 Dungeon game, binary search, DP
  27. 1125 Smallest sufficient team, DP, bit manipulation
  28. 68 Text justification, string
  29. 847 shortest path visiting all nodes, DP, BFS
  30. 732 My calendar III, segment tree, ordered map

Actionable Items

I only studied and learned the top nine hard level algorithms, still I have 21 algorithms to review. Now it is 11:34 PM. 

  1. 727 Minimum windows subsequence - DP, sliding window
  2. 715 Range Module, Segment tree, ordered map
  3. 552 Student attendance record II, DP
  4. 465 Optimal account balancing 
  5. 1499 Max value of equation, Array, sliding window
  6. 753 Cracking the safe, math, DFS
  7. 1231 Divide Chocolate, Binary search, greedy
  8. 308 Range sum query 2D - Mutable, Binary indexed tree, segment tree
  9. 1293 Shortest path in a grid with obstacles elimination
Life is tough. I should plan early and have more time for those 21 hard level algorithms.