LeetCode Remove All Adjacent Duplicates In String Solution Explained - Java

Sdílet
Vložit
  • čas přidán 23. 08. 2019
  • The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
    Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
    Preparing For Your Coding Interviews? Use These Resources
    --------------------
    (My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
    AlgoCademy - algocademy.com/?referral=nick...
    Daily Coding Interview Questions - bit.ly/3xw1Sqz
    10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
    Follow My Twitter - / nicholaswwhite
    Follow My Instagram - / nickwwhite
    Other Social Media
    ----------------------------------------------
    Discord - / discord
    Twitch - / nickwhitettv
    TikTok - / nickwhitetiktok
    LinkedIn - / nicholas-w-white
    Show Support
    ------------------------------------------------------------------------------
    Patreon - / nick_white
    PayPal - paypal.me/nickwwhite?locale.x...
    Become A Member - / @nickwhite
    #coding #programming #softwareengineering
  • Věda a technologie

Komentáře • 47

  • @ravishraj664
    @ravishraj664 Před 2 lety +5

    short concise and easy to understand. Your way of teaching is perfect. Please keep it up

  • @canobiggs
    @canobiggs Před 4 lety +15

    You're my hero man!

  • @strider_93
    @strider_93 Před 4 lety +9

    How do you handle when char is repeated odd no of times like if string is abbbac

    • @adhishmalviya2408
      @adhishmalviya2408 Před 3 lety +2

      "abac"
      should be the output for this
      I know what you're thinking
      output should have been "c" according to you
      but this problem is diffenret

  • @theyashbansal
    @theyashbansal Před 2 lety +2

    That clap at the beginning blew my ear off 😅

  • @yassinesalimi2155
    @yassinesalimi2155 Před 4 lety +3

    very helpful. Thanks a lot !

  • @canobiggs
    @canobiggs Před 4 lety +4

    Such good stuff in every video

  • @satvikshukla596
    @satvikshukla596 Před 2 lety

    Very very helpful.
    Thank you!!

  • @dharmaputra7394
    @dharmaputra7394 Před 4 lety +6

    Request tutorial graph like a MST, djikstra shortest path

  • @yusenpeng
    @yusenpeng Před rokem +1

    Originally, I used two pointers instead of stack and it turned out to be really inefficient compared to stack. I really appreciate your stack explanation! :)

    • @koikoi91
      @koikoi91 Před rokem

      I would like to see your solution if you dont mind please

  • @smithshelke2036
    @smithshelke2036 Před 4 lety +4

    O(1) space solution ...
    Loop until arr(i) ==arr(i+1) then place 2 pointers a and b at I+2 and i-1 respectively ,and check if elements are equal at those indices, if yes keep expanding the pointers a and b until the elements are not equal then delete.repeat everything till we reach the end of string

  • @biswaranjanbarik4052
    @biswaranjanbarik4052 Před rokem

    U r doing a very very great job thanx that I have found u in youtube.
    I love your videos..
    Love from India..❤💌

  • @krishnavar7219
    @krishnavar7219 Před rokem

    the the way you programmed this question it is genius...

  • @simrankak7045
    @simrankak7045 Před 3 lety

    You are Amazing dude thankyou

  • @044_karan9
    @044_karan9 Před 3 lety +7

    what was that noise in the starting of the video !!

    • @sadmanabedin1203
      @sadmanabedin1203 Před 3 lety +1

      I thought the sound came from my side, your comment just assured me that I am safe here 😂

  • @ketansharma6955
    @ketansharma6955 Před rokem

    I have never used stack with indices, can someone share me some problems, which use the same. Thanks.

  • @dalindu7572
    @dalindu7572 Před 3 lety +3

    why using a char[] as stack instead of using STACK ADT?

    • @simonkaranja3811
      @simonkaranja3811 Před 2 lety

      wondering too!!
      I did this easily using a Stack
      class Solution {
      public String removeDuplicates(String s) {
      Stack stack = new Stack();
      StringBuilder sb = new StringBuilder();
      for(int i=0;i

  • @nishantvaishla5752
    @nishantvaishla5752 Před 3 lety

    thanks bro

  • @chodingninjas7415
    @chodingninjas7415 Před 4 lety +1

    u are the best

  • @unknownman1
    @unknownman1 Před 3 lety +1

    7:25 how does string from 0,2 returns c,a. Instead of 0,2 it should be 0,1?

    • @gaurav91pandey
      @gaurav91pandey Před 3 lety +3

      0 is inclusive, 2 is exclusive

    • @theweekday8158
      @theweekday8158 Před 2 lety

      @@gaurav91pandey actually the 2 in (stack, 0, 2 ) is the offset and not the exclusive index. 0 is the starting index and 2 here tells about the length from index 0 till which it will copy from stack into the new string.

  • @karanjindal1860
    @karanjindal1860 Před 4 lety +4

    "aaaaaaaa" this doesn't work

  • @guyfromgalaxy
    @guyfromgalaxy Před 2 lety

    Can do with inplace string manipulation , without using extra memory (credit to you as I learnt this trick from your previous video, so thank you! :) )

    • @koikoi91
      @koikoi91 Před rokem

      I would like to see your solution if you dont mind please

  • @CodeSuccessChronicle
    @CodeSuccessChronicle Před 3 lety

    Brother you didn’t write a 0 assignment in case there’s a duplicate how can stack change then ....

  • @samvid74
    @samvid74 Před 2 lety

    It does not work with aaab result is ab should be b

  • @mohdzebalam8706
    @mohdzebalam8706 Před 3 lety

    space is o(1)

  • @KoushikChowdhury2016
    @KoushikChowdhury2016 Před 4 měsíci

    string removeDuplicates(string s) {
    int i = 0, n = s.length();
    for (int j = 0; j < n; ++j, ++i) {
    s[i] = s[j];
    if (i > 0 && s[i - 1] == s[i]) // count = 2
    i -= 2;
    }
    return s.substr(0, i);
    }
    This has SC: O(1)

  • @varunsadhu9060
    @varunsadhu9060 Před 4 lety

    It doesn't work for TC aabbccccbapq

  • @abhijeetmishra4300
    @abhijeetmishra4300 Před 4 lety +2

    wrong solution bro

  • @paraskumar693
    @paraskumar693 Před 3 lety

    my code is showing TLE for 9000+ characters

  • @sophiezhang6516
    @sophiezhang6516 Před 4 lety

    i like your videos, but this solution doesn't work

  • @infotainment7123
    @infotainment7123 Před 4 lety

    your code doesnt work for "geeksforgeek"

  • @gauravagarwal6565
    @gauravagarwal6565 Před 2 lety

    *With no extra space*
    ---------------------------------
    StringBuilder sb = new StringBuilder(s);
    int i = 0;
    while(i0)
    i --;
    }
    else{
    i++;
    }
    }
    return sb.toString();

  • @harshitsharma4063
    @harshitsharma4063 Před 3 lety

    acaaabssscp this doesn't work, I believe u thought of only two consecutive are adjacent!! Btw np , thanks keep posting

  • @HarishAmarnath
    @HarishAmarnath Před 4 lety

    seriously you can figure out without o(n) spaces ? , you can iterate the string with 2 a and b pointers . stop the first pointer a when a and a-1 index is equal , then paste a+1th index item at a-1 , also make b=a+1; a=a-2;..... keep going until list ends.

    • @yashmishra12
      @yashmishra12 Před 4 lety

      Do you have the code for this approach?

  • @harshdeepsinghful
    @harshdeepsinghful Před 3 lety

    Without extra space
    class Solution {
    public String removeDuplicates(String S) {
    //String s="abbaca";
    for(int i=0;i

    • @piyushmathpal4244
      @piyushmathpal4244 Před 2 lety

      why this line two times ?
      s=s.substring(0,i)+s.substring(i+1, s.length());
      Also, Can you please confirm if the solution is working for the input "abbaca"?