Minimum Cost for Cutting Cake I & II | Thought Process | Leetcode 3218 | 3219 | codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=aim6BEc9aMk



Duration: 39:26
3,851 views
175


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 36th Video of our Playlist "GREEDY TECHNIQUE : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a very good Greedy Problem : Minimum Cost for Cutting Cake I & II | Simple Thought Process | Leetcode 3218 | 3219 | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Minimum Cost for Cutting Cake I & II | Simple Thought Process | Leetcode 3218 | 3219 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : PART-1 : https://leetcode.com/problems/minimum...
PART-2 : https://leetcode.com/problems/minimum...


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
The given approach is designed to compute the minimum cost of cutting a grid of size m x n using specified horizontal and vertical cuts. Here's a summary of the approach:
Input Preparation: The function minimumCost takes parameters m and n representing the dimensions of the grid, and two vectors horizontalCut and verticalCut which contain the positions where the grid will be cut horizontally and vertically, respectively.

Sorting: Both horizontalCut and verticalCut vectors are sorted in descending order. This ensures that we start cutting from the largest to the smallest segment, which helps in minimizing costs effectively.

Initialization:

i and j are initialized to traverse through horizontalCut and verticalCut respectively.
horizontalPieces and verticalPieces are initialized to 1, representing the current number of horizontal and vertical segments.
Cost Calculation:

Using a while loop, the algorithm compares the current largest segment available in horizontalCut[i] and verticalCut[j].
If horizontalCut[i] is larger or equal to verticalCut[j], it adds the cost of cutting horizontalCut[i] multiplied by verticalPieces to the result. Then it increments horizontalPieces and moves to the next segment in horizontalCut.
Otherwise, it adds the cost of cutting verticalCut[j] multiplied by horizontalPieces to the result, increments verticalPieces, and moves to the next segment in verticalCut.
Completion of Cutting:

After the while loop, any remaining segments in horizontalCut or verticalCut are processed using two separate while loops to ensure all segments are accounted for in the final cost calculation.
Result: The function returns result, which represents the minimum cost required to completely cut the grid according to the specified cuts.

This approach effectively computes the minimum cost by dynamically adjusting the number of pieces and accumulating costs based on the largest available segment at each step, ensuring optimal cutting strategy.



✨ Timelines✨
00:00 - Introduction

#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 #newyear2024




Other Videos By codestorywithMIK


2024-07-22Sort the Jumbled Numbers | 2 Approaches | Leetcode 2191 | codestorywithMIK
2024-07-20Minimum Operations to Make Array Equal to Target | Minimum Number of Increments|Leetcode 3229 & 1526
2024-07-19Build a Matrix With Conditions | BFS | DFS | Detailed Explanation | Leetcode 2392 | codestorywithMIK
2024-07-19Palindrome Partitioning | Using Blue Print | DP On Strings | Leetcode 131 | DP Concepts & Qns-27
2024-07-18Find Valid Matrix Given Row and Column Sums | Simple Approach | Leetcode 1605 | codestorywithMIK
2024-07-18Number of Good Leaf Nodes Pairs | Simple DFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-17Lucky Numbers in a Matrix | 2 Approaches | Dry Run | Leetcode 1380 | codestorywithMIK
2024-07-16Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-14Step-By-Step Directions From a Binary Tree Node to Another | 2 Approaches | Leetcode 2096
2024-07-13Create Binary Tree From Descriptions | Simplest Approach | Leetcode 2196 | codestorywithMIK
2024-07-12Minimum Cost for Cutting Cake I & II | Thought Process | Leetcode 3218 | 3219 | codestorywithMIK
2024-07-11Maximum Score From Removing Substrings | 2 Approaches | With Proof | Leetcode 1717
2024-07-09Reverse Substrings Between Each Pair of Parentheses | 2 Approaches | Leetcode 1190 |codestorywithMIK
2024-07-08Crawler Log Folder | 2 Approaches | Dry Runs | Leetcode 1598 | codestorywithMIK
2024-07-07Average Waiting Time | Simple Simulation | Leetcode 1701 | codestorywithMIK
2024-07-06Range Update Query | Lazy Propagation | Segment Tree Concepts & Qns | Video 7 | codestorywithMIK
2024-07-06Find the Winner of the Circular Game | 3 Approaches | Leetcode 1823 | codestorywithMIK
2024-07-05Pass the Pillow | 2 Approaches | Easy Explanations | Leetcode 2582 | codestorywithMIK
2024-07-05Water Bottles | 3 Approaches | Easy Explanations | Leetcode 1518 | codestorywithMIK
2024-07-02Minimum Difference Between Largest and Smallest Value in Three Moves | 2 Approaches | Leetcode 1509
2024-07-02Merge Nodes in Between Zeros | 2 Approaches | Leap Of Faith | Leetcode 2181 | codestorywithMIK