Crawler Log Folder | 2 Approaches | Dry Runs | Leetcode 1598 | codestorywithMIK
Vložit
- čas přidán 8. 07. 2024
- Whatsapp Community Link : www.whatsapp.com/channel/0029...
This is the 48th 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 | 2 Approaches | Dry Runs | Leetcode 1598 | 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 | 2 Approaches | Dry Runs | Leetcode 1598 | codestorywithMIK
Company Tags : Google, and some other company Online Assessment problem with slight variation
My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/crawler...
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My Recursion Concepts Playlist : • Introduction | Recursi...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
Approach-1: Using Simple Simulation
Description: This approach uses a single integer variable depth to simulate the traversal of folders. The depth variable is incremented when entering a folder and decremented when moving up a directory ("../"), ensuring it doesn't go below zero. The "./" operations are ignored as they do not change the directory.
Time Complexity: O(n), where n is the number of operations. Each operation is processed once.
Space Complexity: O(1), as only a single integer variable is used regardless of the input size.
Approach-2: Using Stack for Simulation
Description: This approach uses a stack to simulate the traversal of folders. Each folder name is pushed onto the stack, and when encountering "../", the stack is popped if it's not empty. The "./" operations are ignored. The size of the stack at the end represents the current depth in the folder structure.
Time Complexity: O(n), where n is the number of operations. Each operation is processed once.
Space Complexity: O(n), as the stack can potentially grow up to the number of operations if no "../" commands are encountered.
Summary
Both approaches efficiently simulate the traversal of the folder structure based on the operations given. The first approach uses a single integer to keep track of the depth, resulting in constant space usage, making it more space-efficient. The second approach uses a stack, which is more intuitive in terms of simulating folder traversal but requires additional space proportional to the number of operations. Both have the same time complexity of O(n).
✨ 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
Mai apko kafi phle se follow kr rha and itta detail me dsa ke vids shyd hi koi bnata hai . Thanks bhaiya and waiting for 57k
Good morning sir, just submitted my solution and got notification of your video ❤
congratulations for your 500 day streak 🙌🙌🙌🙌🙌🙌
we should always use equals function instead of ==
with strings..
that's a sonar bug also..
Bhai aise hi roz upload karte raho mai aapko dekh kar proper consistent leetcode chalu kar diya hai
NICE SUPER EXCELLENT MOTIVATED
Bro how u uploaded this video at 7 or 6 am !! Like when did u even recorded and edited it
Jaldi uth jata h bhai humara 😮
Beta Tu aam kha ghutli na dekh
Is level ka motivation chaie yaar life me. koshish kar raha hu mai bhi
Good morning. I did it using stack 😊
Hi priyanshi I know you 💞
Thanks a lot bhaiya ❤❤
sir os, dbms jaise core subs ke lie guide kardo ya resources bata do kaise padhe for interviews?
Good morning bhaiya 😊
Stack is useful if asked to trace the actual path back (see Leetcode editorial)
Congrats for 56K
It was easy 🎉
keep doing it ....
Maximum Product of Word Lengths | LeetCode 318 pe vdo bna do sir
Bhaiya Thanks for this video tooooo........can you make a video on Leetcode 306. Additive Number
500days man legendary
500 days 🔥
class Solution {
public:
int minOperations(vector& logs) {
int count =0;
int n=logs.size();
int i =0;
while(n>i){
if(logs[i]=="../"){
if(count>0){
count--;
}
}else if(logs[i]!="./"){
count++;
}
i++;
}
return count;
}
};
class Solution {
public:
int minOperations(vector& logs) {
stack st;
for(auto s : logs){
string str = s.substr(0,s.size()-1);
cout
|| Java Solutions ||
// 1. With Stack
class Solution {
public int minOperations(String[] logs) {
Stack st = new Stack();
for(int i=0; i
for(string &log:logs) ka faeda kya hai & na lagae to kya farak padega ???
By using a reference(&), you avoid copying each string in the container. Strings can be large and expensive to copy, so this can result in significant performance improvements, especially when the container has a large number of elements.
@@gui-codes ohhh thanks
class Solution {
public int minOperations(String[] logs) {
int level=1;
for(String op : logs){
if(op.equals("./")){
continue;
}
else if(op.equals("../")){
if(level != 1){
level--;
}
}
else{
level++;
}
}
return level-1;
}
}
a good simple problem to build confidence..
Approach
- Initiate the count with zero.
- Iterate through the whole logs and each time when "../" appears if count >0 then there will be decreament in count.
- When "./" appears then leave the count as it is.
- when "x/" appears increase the count by 1.
- Finally when getting out of the loop if count