402. Remove K Digits | Monotonic Stack | Greedy | Brute Force - Optimal Solution

In this video, I'll talk about how to solve Leetcode 402. Remove K Digits | Monotonic Stack | Greedy | Brute Force - Optimal Solution
Stack Playlist - • Complete Stack & Queue...
Greedy Playlist - • Complete Greedy Intui...
Similar Problem - • 3106. Lexicographicall...
Let's Connect:
📝Linkedin: / aryan-mittal-0077
📸 Instagram: / ez.pz.dsa
📱Telegram : t.me/aryan_mittal_group
🤖 Github: github.com/aryan-0077
About Me:
I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Пікірлер: 25

  • @ARYANMITTAL
    @ARYANMITTAL3 ай бұрын

    Practice StacK & Monotonic Stack Problems - kzread.info/head/PLEL7R4Pm6EmDSG2vFQN8S04AQfLHC0jR7 . Latest Video on *Hindi Channel* - kzread.info/dash/bejne/iHWEmaOTgsjdc84.html

  • @AJ-xc3ks
    @AJ-xc3ks3 ай бұрын

    Bro and we reversing it or using str function so these t.c will be added nn

  • @rakeshchahal8330
    @rakeshchahal83303 ай бұрын

    class Solution { public: string removeKdigits(string nums, int k) { int n = nums.size(); string ans=""; for(int i=0;inums[i] && k>0) { ans.pop_back(); k--; } ans.push_back(nums[i]); } while(!ans.empty() && k>0) { ans.pop_back(); k--; } int i=0; while(ans[i]=='0' && i

  • @rishabhgupta6179
    @rishabhgupta61793 ай бұрын

    Hi Arayan , I am still not able to understand why removing numbers which are greater than the current number will ensure least possible ans . If possible , do you have an easy explanation.

  • @siddharthkachhia4829
    @siddharthkachhia48293 ай бұрын

    I was try to do it by DP but it gives me TLE😅

  • @codingkart245
    @codingkart2453 ай бұрын

    idk whether I'm the one who misses his energetic starting this time.

  • @satwiktatikonda764
    @satwiktatikonda7643 ай бұрын

    bro waiting for 100days series :(

  • @ARYANMITTAL

    @ARYANMITTAL

    3 ай бұрын

    Yaa bro, I’ll planning to bring it in Hindi, so doing preparations for it, will be available on Hindi Channel ❤️❤️

  • @user-yl4vp2ox8v
    @user-yl4vp2ox8v2 ай бұрын

    #include int rever ( int num) { int rev = 0 ; while(num > 0) { int reminder = num%10; rev = rev*10 + reminder; num = num/10; } return rev ; } int main() { int num = 125; int rev = 0 ; int pos = 1 ; while (num > 0 ) { int reminder = num %10; if (pos == 1 || pos == 4) { rev = 10 *rev + reminder; pos++; } pos++; num = num/10; } int rev1 = rever(rev); printf("%d", rev1); }

  • @user-cv6ed5cb9c
    @user-cv6ed5cb9c3 ай бұрын

    For me it gave memory limit exceeded for test case 42/43 . The code was same : class Solution { public: string removeKdigits(string num, int k) { stack st; for(auto i:num){ while(!st.empty() && i0 ){ st.pop();k--; } st.push(i); } while(k>0 && !st.empty())st.pop(),k--; string ans=""; while(!st.empty()){ ans=ans+st.top(); st.pop(); } int endIdx=0; for(int i=ans.length()-1;i>=0;i--){ if(ans[i]!='0'){ endIdx=i; break; } } ans=ans.substr(0,endIdx+1); if(ans=="")return "0"; reverse(ans.begin(),ans.end()); return ans; } };

  • @kabir2190

    @kabir2190

    3 ай бұрын

    same bro 🤣 then i solved it using deque try using deque

  • @selfgrowthsigma

    @selfgrowthsigma

    3 ай бұрын

    class Solution { public: string removeKdigits(string nums, int k) { int n=nums.size(); if(n==k) return "0"; stackst; for(int i=0;inums[i] && k>0){ k--; st.pop(); } st.push(nums[i]); } while(!st.empty() && k>0){ k--; st.pop(); } string ans=""; while(!st.empty()){ ans+=st.top(); st.pop(); } reverse(ans.begin(),ans.end()); for(int i=0;i

  • @YashAggarwal-ri6kt

    @YashAggarwal-ri6kt

    3 ай бұрын

    The problem us u wrote ans=ans+st.top() Try ans+=st.top()

  • @kabir2190

    @kabir2190

    3 ай бұрын

    @@YashAggarwal-ri6kt they are different?😕

  • @ARYANMITTAL

    @ARYANMITTAL

    3 ай бұрын

    Yes sir, they are different, in cpp += is an overloaded operator for charcters and performs same as push_back() which is O(1) operation, while ans = ans + is an O(n) operation

  • @Ramgangakumar
    @RamgangakumarАй бұрын

    bro your voice [isToLow].

  • @satwiktatikonda764
    @satwiktatikonda7643 ай бұрын

    Is there any reason for uploading 100 days series in Hindi channel Ppl like me from South india are also follows ur videos bro

  • @tkab1205
    @tkab12053 ай бұрын

    Aapka sound bohot low arha ha

  • @khatriiedits3606
    @khatriiedits36063 ай бұрын

    Too long video

  • @ganeshsharma5810
    @ganeshsharma58103 ай бұрын

    bro can you explain the question in english hindi mix so that we understand the problem more easily

  • @RohanSharma-tl9wh
    @RohanSharma-tl9wh3 ай бұрын

    Aryan please share your leetcode username

  • @user-yl4vp2ox8v
    @user-yl4vp2ox8v2 ай бұрын

    #include int rever ( int num) { int rev = 0 ; while(num > 0) { int reminder = num%10; rev = rev*10 + reminder; num = num/10; } return rev ; } int main() { int num = 125; int rev = 0 ; int pos = 1 ; while (num > 0 ) { int reminder = num %10; if (pos == 1 || pos == 4) { rev = 10 *rev + reminder; pos++; } pos++; num = num/10; } int rev1 = rever(rev); printf("%d", rev1); }

Келесі