Furthest Building You Can Reach | What is Lazy Greedy | Recursion | Memoization | Leetcode 1642
iPad PDF Notes - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Leetcode-1642-Furthest%20Building%20You%20Can%20Reach.pdf
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 28th Video of our Playlist "Greedy : Popular Interview Problems".
We will try to understand the thought process behind solving such Qns.
Problem Name : Least Number of Unique Integers after K Removals | Leetcode 642
Company Tags : Microsoft, Google
My solutions on Github :
Heap - (Lazy Greedy) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Heap/Furthest%20Building%20You%20Can%20Reach.cpp
Recursion + Memo - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/DP/Furthest%20Building%20You%20Can%20Reach.cpp
Leetcode Link : https://leetcode.com/problems/furthest-building-you-can-reach/
Approach Summary :
Approach-1 (Recur + Memo) - Explore both options. Try with bricks and try with ladder and find the max you reach from both. Return the furthest you can go.
Approach-2 (Lazy Greedy) - The person has the option to use either bricks or ladders to overcome the height difference between adjacent buildings. The solution iterates through the buildings, and for each pair of consecutive buildings, it calculates the height difference (diff). If the difference can be covered using available bricks, the bricks are used, and the difference is added to a priority queue. If bricks are insufficient, it checks if using a ladder would be a better choice by comparing with the maximum difference covered using bricks in the past. If a ladder is used, it decrements the available ladders. The process continues until either the person runs out of buildings or resources. The function returns the index of the last building reached. The priority queue helps keep track of the maximum bricks used, allowing for potential recovery if a ladder becomes available later.
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Timelines : ⏰
00:00 - Problem Explanation
6:49 - Why Greedy Fails ?
11:47 - Recursion + Memoization - Tree Diagram
21:18 - Coding Recursion + Memoization
26:41 - Lazy Greedy ??? Intuition
37:54 - Story To Code
45:15 - Coding Lazy Greedy
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear