Crawler Log Folder | 2 Approaches | Dry Runs | Leetcode 1598 | codestorywithMIK

Sdílet
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

Komentáře • 31

  • @RahulRaj-dh2rr
    @RahulRaj-dh2rr Před 18 dny +4

    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

  • @unemployed-coder
    @unemployed-coder Před 18 dny +7

    Good morning sir, just submitted my solution and got notification of your video ❤

  • @user-zs8of1yl2v
    @user-zs8of1yl2v Před 17 dny +4

    congratulations for your 500 day streak 🙌🙌🙌🙌🙌🙌

  • @aizad786iqbal
    @aizad786iqbal Před 17 dny +1

    we should always use equals function instead of ==
    with strings..
    that's a sonar bug also..

  • @AdityaVerma-hh1ox
    @AdityaVerma-hh1ox Před 18 dny +1

    Bhai aise hi roz upload karte raho mai aapko dekh kar proper consistent leetcode chalu kar diya hai

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 Před 17 dny +1

    NICE SUPER EXCELLENT MOTIVATED

  • @higuys450
    @higuys450 Před 18 dny +8

    Bro how u uploaded this video at 7 or 6 am !! Like when did u even recorded and edited it

    • @rishhills
      @rishhills Před 18 dny +3

      Jaldi uth jata h bhai humara 😮

    • @jeehub041
      @jeehub041 Před 17 dny

      Beta Tu aam kha ghutli na dekh

    • @gui-codes
      @gui-codes Před 17 dny

      Is level ka motivation chaie yaar life me. koshish kar raha hu mai bhi

  • @ugcwithaddi
    @ugcwithaddi Před 18 dny +2

    Good morning. I did it using stack 😊

  • @gauravbanerjee2898
    @gauravbanerjee2898 Před 18 dny +1

    Thanks a lot bhaiya ❤❤

  • @zebra-er6xc
    @zebra-er6xc Před 18 dny

    sir os, dbms jaise core subs ke lie guide kardo ya resources bata do kaise padhe for interviews?

  • @Coder_Buzz07
    @Coder_Buzz07 Před 18 dny +1

    Good morning bhaiya 😊

  • @priyanshkumariitd
    @priyanshkumariitd Před 18 dny

    Stack is useful if asked to trace the actual path back (see Leetcode editorial)

  • @gui-codes
    @gui-codes Před 17 dny

    Congrats for 56K

  • @peterfromengland8663
    @peterfromengland8663 Před 18 dny +1

    It was easy 🎉

  • @RahulSharma-ht2xz
    @RahulSharma-ht2xz Před 18 dny +1

    keep doing it ....

  • @amarnathtripathy4350
    @amarnathtripathy4350 Před 18 dny

    Maximum Product of Word Lengths | LeetCode 318 pe vdo bna do sir

  • @contestSolutions88
    @contestSolutions88 Před 18 dny

    Bhaiya Thanks for this video tooooo........can you make a video on Leetcode 306. Additive Number

  • @Nofaltuguy1
    @Nofaltuguy1 Před 18 dny +1

    500days man legendary

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i Před 18 dny +1

    500 days 🔥

  • @user-zs8of1yl2v
    @user-zs8of1yl2v Před 17 dny

    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;

    }
    };

  • @utkarshsahay9908
    @utkarshsahay9908 Před 18 dny

    class Solution {
    public:
    int minOperations(vector& logs) {
    stack st;
    for(auto s : logs){
    string str = s.substr(0,s.size()-1);
    cout

  • @nikhilhaspe2734
    @nikhilhaspe2734 Před 18 dny

    || Java Solutions ||
    // 1. With Stack
    class Solution {
    public int minOperations(String[] logs) {
    Stack st = new Stack();
    for(int i=0; i

  • @Manjot_singh2002
    @Manjot_singh2002 Před 18 dny

    for(string &log:logs) ka faeda kya hai & na lagae to kya farak padega ???

    • @gui-codes
      @gui-codes Před 17 dny

      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.

    • @Manjot_singh2002
      @Manjot_singh2002 Před 16 dny

      @@gui-codes ohhh thanks

  • @aizad786iqbal
    @aizad786iqbal Před 18 dny

    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..

  • @tarunsingh2480
    @tarunsingh2480 Před 18 dny +1

    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