Water Bottles | 3 Approaches | Easy Explanations | Leetcode 1518 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 47th Video of our Playlist "Leetcode Easy : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good practice problem : Water Bottles | 3 Approaches | Easy Explanations | Leetcode 1518 | 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 : Water Bottles | 3 Approaches | Easy Explanations | Leetcode 1518 | codestorywithMIK
Company Tags : AMAZON
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/water-b...
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 :
Approach-1 (Simple simulation)
Time Complexity: O(numBottles)
Space Complexity: O(1)
Summary: This approach simulates the process of consuming water bottles and exchanging the empty ones for full bottles. It repeatedly consumes and exchanges until the number of bottles left is less than the exchange threshold. The total consumed bottles are returned.
Approach-2 (Improvement on Approach-1)
Time Complexity: O(lognumExchange(numBottles))
Space Complexity: O(1)
Summary: This approach optimizes the first one by using integer division and modulo operations to calculate how many new full bottles can be obtained from empty bottles in each iteration. It reduces the number of iterations needed to complete the exchange process.
Approach-3 (Using maths)
Time Complexity: O(1)
Space Complexity: O(1)
Summary: This approach uses a mathematical formula to directly calculate the total number of consumed bottles. It leverages the insight that the total number of bottles is the initial count plus the number of additional bottles obtained through exchanges, which is derived from simple arithmetic operations.
✨ Timelines✨
00:00 - Introduction
4:38 - Approach-1
13:17 - Approach-2
19:41 - Coding Approach-1 and Approach-2
23:06 - Approach-3
30:23 - Coding Approach-3
#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