Minimum Number of Operations to Move All Balls to Each Box | Leetcode 1769 | 3 Approaches | MIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
Hi Everyone, this is the 55th video of our Playlist "Strings : Popular Interview Problems".
Now we will be solving a very good problem based on string - Minimum Number of Operations to Move All Balls to Each Box | Leetcode 1769 | 3 Approaches | codestorywithMIK
Problem Name : Minimum Number of Operations to Move All Balls to Each Box | Leetcode 1769 | 3 Approaches | codestorywithMIK
Company Tags : Will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/strings/Minimum Number of Operations to Move All Balls to Each Box.cpp
Leetcode Link : https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Segment Tree Concepts Playlist : • Segment Tree | Introduction | Basics ...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Video Summary :
Approach 1: Brute Force Using HashSet
This approach identifies the positions of all boxes containing balls and stores them in a HashSet. For each box, the distances to all the positions in the set are calculated and summed to determine the total moves required.
Approach 2: Brute Force with O(1) Space
Instead of storing the positions of boxes with balls, this approach iterates through the string directly. For each box, it calculates the distance to every other box containing a ball and updates the result accordingly.
Approach 3: Optimal Using Cumulative Sum
This approach uses cumulative sums to calculate the moves. It first computes the moves required for all balls to the left of each box, then calculates the moves for all balls to the right, combining the results for the final answer.
✨ Timelines✨
00:00 - Introduction
00:22 - Motivation
01:40 - Problem Explanation
05:48 - Brute Force-1
10:22 - Brute Force-2
15:21 - Optimal Approach
31:08 - Simplifying code
41:09 - Coding it up
#MIK #mik #Mik
#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 #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik