LeetCode Remove All Adjacent Duplicates In String Solution Explained - Java

  Рет қаралды 28,927

Nick White

Nick White

Күн бұрын

Пікірлер: 47
@ravishraj664
@ravishraj664 2 жыл бұрын
short concise and easy to understand. Your way of teaching is perfect. Please keep it up
@smithshelke2036
@smithshelke2036 5 жыл бұрын
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
@deepakvm1475
@deepakvm1475 3 жыл бұрын
nice
@yusenpeng
@yusenpeng Жыл бұрын
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 Жыл бұрын
I would like to see your solution if you dont mind please
@krishnavar7219
@krishnavar7219 Жыл бұрын
the the way you programmed this question it is genius...
@strider_93
@strider_93 5 жыл бұрын
How do you handle when char is repeated odd no of times like if string is abbbac
@adhishmalviya2408
@adhishmalviya2408 4 жыл бұрын
"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
@dharmaputra7394
@dharmaputra7394 5 жыл бұрын
Request tutorial graph like a MST, djikstra shortest path
@044_karan9
@044_karan9 4 жыл бұрын
what was that noise in the starting of the video !!
@sadmanabedin1203
@sadmanabedin1203 4 жыл бұрын
I thought the sound came from my side, your comment just assured me that I am safe here 😂
@theyashbansal
@theyashbansal 3 жыл бұрын
That clap at the beginning blew my ear off 😅
@canobiggs
@canobiggs 5 жыл бұрын
You're my hero man!
@biswaranjanbarik4052
@biswaranjanbarik4052 2 жыл бұрын
U r doing a very very great job thanx that I have found u in youtube. I love your videos.. Love from India..❤💌
@dalindu7572
@dalindu7572 4 жыл бұрын
why using a char[] as stack instead of using STACK ADT?
@simonkaranja3811
@simonkaranja3811 2 жыл бұрын
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
@karanjindal1860
@karanjindal1860 4 жыл бұрын
"aaaaaaaa" this doesn't work
@CodeSuccessChronicle
@CodeSuccessChronicle 3 жыл бұрын
Brother you didn’t write a 0 assignment in case there’s a duplicate how can stack change then ....
@unknownman1
@unknownman1 4 жыл бұрын
7:25 how does string from 0,2 returns c,a. Instead of 0,2 it should be 0,1?
@gaurav91pandey
@gaurav91pandey 3 жыл бұрын
0 is inclusive, 2 is exclusive
@theweekday8158
@theweekday8158 2 жыл бұрын
@@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.
@canobiggs
@canobiggs 5 жыл бұрын
Such good stuff in every video
@guyfromgalaxy
@guyfromgalaxy 2 жыл бұрын
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 Жыл бұрын
I would like to see your solution if you dont mind please
@ketansharma6955
@ketansharma6955 Жыл бұрын
I have never used stack with indices, can someone share me some problems, which use the same. Thanks.
@samvid74
@samvid74 2 жыл бұрын
It does not work with aaab result is ab should be b
@yassinesalimi2155
@yassinesalimi2155 5 жыл бұрын
very helpful. Thanks a lot !
@satvikshukla596
@satvikshukla596 2 жыл бұрын
Very very helpful. Thank you!!
@KoushikChowdhury2016
@KoushikChowdhury2016 8 ай бұрын
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)
@abhijeetmishra4300
@abhijeetmishra4300 4 жыл бұрын
wrong solution bro
@paraskumar693
@paraskumar693 3 жыл бұрын
my code is showing TLE for 9000+ characters
@simrankak7045
@simrankak7045 3 жыл бұрын
You are Amazing dude thankyou
@sophiezhang6516
@sophiezhang6516 4 жыл бұрын
i like your videos, but this solution doesn't work
@varunsadhu9060
@varunsadhu9060 5 жыл бұрын
It doesn't work for TC aabbccccbapq
@mohdzebalam8706
@mohdzebalam8706 3 жыл бұрын
space is o(1)
@chodingninjas7415
@chodingninjas7415 5 жыл бұрын
u are the best
@infotainment7123
@infotainment7123 4 жыл бұрын
your code doesnt work for "geeksforgeek"
@gauravagarwal6565
@gauravagarwal6565 3 жыл бұрын
*With no extra space* --------------------------------- StringBuilder sb = new StringBuilder(s); int i = 0; while(i0) i --; } else{ i++; } } return sb.toString();
@nishantvaishla5752
@nishantvaishla5752 3 жыл бұрын
thanks bro
@harshdeepsinghful
@harshdeepsinghful 3 жыл бұрын
Without extra space class Solution { public String removeDuplicates(String S) { //String s="abbaca"; for(int i=0;i
@piyushmathpal4244
@piyushmathpal4244 3 жыл бұрын
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"?
@harshitsharma4063
@harshitsharma4063 4 жыл бұрын
acaaabssscp this doesn't work, I believe u thought of only two consecutive are adjacent!! Btw np , thanks keep posting
@HarishAmarnath
@HarishAmarnath 4 жыл бұрын
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 4 жыл бұрын
Do you have the code for this approach?
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
How I Failed the Google Coding Interview (and lessons I learned)
14:24
LeetCode Buddy Strings Solution Explained - Java
9:21
Nick White
Рет қаралды 10 М.
Self Taught Programmers... Listen Up.
11:21
Nick White
Рет қаралды 1,1 МЛН
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 282 М.
Coding Is Changing...Here Is What You NEED To Know
9:26
Nick White
Рет қаралды 65 М.
Recursively remove all adjacent duplicates | Recursion | C++
15:08
Ayushi Sharma
Рет қаралды 10 М.
you will never ask about pointers again after watching this video
8:03
LeetCode Island Perimeter Solution Explained - Java
7:28
Nick White
Рет қаралды 17 М.
LeetCode Open the Lock Solution Explained - Java
15:35
Nick White
Рет қаралды 21 М.
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24