1190. Reverse Substrings Between Each Pair of Parentheses | StacK | Wormhole Teleportation technique

  Рет қаралды 5,044

Aryan Mittal

Aryan Mittal

Күн бұрын

In this video, I'll talk about how to solve Leetcode 1190. Reverse Substrings Between Each Pair of Parentheses | StacK | Wormhole Teleportation technique | O(n) time
Let's Connect:
📱Discord (Join Community) : / discord
📝Linkedin: / aryan-mittal-0077
📸 Instagram: / codewitharyanbhai
💻 Twitter - / aryan_mittal007
🤖 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 :)
✨ Timelines✨
0:00 - Problem Explanation
00:46 - Stack O(n^2) approach
8:12 - Wormhole Teleportation technique O(n) time
✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Пікірлер: 29
@rajrajesh1669
@rajrajesh1669 22 күн бұрын
Been solving daily challenges for 6 months now, warmhole technique was smtg new for me!!! Thank you Aryan I learnt yet another technique.
@sumitgupta310
@sumitgupta310 23 күн бұрын
Second approach 🔥
@think_n_code
@think_n_code 22 күн бұрын
Did you find any lectures that explain in deep the Wormhole Teleportation technique?
@kondekarvaishnavi2348
@kondekarvaishnavi2348 22 күн бұрын
After long gap aryan is back with super content. Thankyou aryan🥳🥳
@rishabhranjan5162
@rishabhranjan5162 22 күн бұрын
bruh he was uploading every single day.
@aarkojha5710
@aarkojha5710 16 күн бұрын
actually in the first method theres an issue, we are not removing the opening bracket from the ans. To do so just write in the loop for closing bracket, after the while statement, if(st.top()=='(') st.pop()
@user-wq3jq7wc3s
@user-wq3jq7wc3s 22 күн бұрын
gajab solution!!
@italk-gj5kk
@italk-gj5kk 22 күн бұрын
wonderful explanantion
@akmarkan2490
@akmarkan2490 23 күн бұрын
Thanks Bro
@shivamgurjar8979
@shivamgurjar8979 22 күн бұрын
The second solution is just so good
@RatulRoy-gc8yj
@RatulRoy-gc8yj 22 күн бұрын
@Aryan bhaiya can u explain the outward portion again like in 11:32 when we are going from index 6 to 9 but in outward direction this part why we did ?
@harshsharma9322
@harshsharma9322 23 күн бұрын
Perfect timing bhai! Thanks
@ARYANMITTAL
@ARYANMITTAL 23 күн бұрын
Kyaa baat hai Harsh bhai 🫡❤️
@parasd2802
@parasd2802 22 күн бұрын
bhai that wormhole technique is so good.
@naamnhibataunga5897
@naamnhibataunga5897 22 күн бұрын
didn't knew about the wormhole teleportation technique... this was my initial solution : O(n^2) class Solution { public: string reverseParentheses(string s) { stack s1; stack s2; string word = ""; int i = 0; int n = s.length(); // Process characters before the first '(' while (i < n && s[i] != '(') { word += s[i++]; } string str = ""; while (i < n) { char c = s[i]; if (c == '(') { s1.push('('); s2.push(str); str = ""; } else if (c == ')') { if (!s1.empty()) { s1.pop(); reverse(str.begin(), str.end()); if (!s2.empty()) { str = s2.top() + str; s2.pop(); } } } else { str += c; } i++; } word += str; return word; } };
@abhayraghuwanshi4869
@abhayraghuwanshi4869 18 күн бұрын
Hello everyone, Can you suggest more questions where we can use warmhole techniques?
@divyagarg4821
@divyagarg4821 22 күн бұрын
Please cover 1017 th problem of leetcode
@mdyeamentalukder1473
@mdyeamentalukder1473 22 күн бұрын
can we solve it useing prefix sum?
@darth_vader_11
@darth_vader_11 22 күн бұрын
Watched twice for understanding wormhole teleportation technique, still little difficult to understand 🤒
@nooob_coder
@nooob_coder 22 күн бұрын
dry run bro on test cases
@rev_krakken70
@rev_krakken70 23 күн бұрын
I solved using recursion.. inherently it is stack only.. is that okay?
@user-sh9to8xr3g
@user-sh9to8xr3g 23 күн бұрын
what!! you guys able to think soln in recursion?
@random-xd7cb
@random-xd7cb 22 күн бұрын
bro send the code
@rev_krakken70
@rev_krakken70 22 күн бұрын
class Solution { int index = 0; public String processString(String s, int length, boolean shouldReverse) { StringBuilder sb = new StringBuilder(); while (index < length && s.charAt(index) != ')') { char currentChar = s.charAt(index); if (currentChar == '(') { index++; sb.append(processString(s, length, true)); } else { sb.append(currentChar); } index++; } return shouldReverse ? sb.reverse().toString() : sb.toString(); } public String reverseParentheses(String s) { StringBuilder sb = new StringBuilder(); int length = s.length(); return processString(s, length, false); } }
@yashparashar6781
@yashparashar6781 22 күн бұрын
Giving runtime error
@akashkataria3218
@akashkataria3218 22 күн бұрын
quality of explanation is now decreasing, i found you from leetcode solutions section and started watching you continuously for your best explanation, but explanation is not as good as your previous videos
@mohit7717
@mohit7717 22 күн бұрын
37/38 test cases passed , what I am doing wrong ? Can Anyone please help me? class Solution { public: string reverseParentheses(string s) { stackst; queueq; st.push(s[0]); int i = 1; while( i
@codingkart245
@codingkart245 22 күн бұрын
my code is working but damn messed up LOL :) -----------------------------------------------------------------------------------------------------------------------------string reverseParentheses(string s) { //store the corresponding opposite indices of parentheses map oppoInd; stack st; for(int i = 0;i= 0){ //if we found a parentheses, go to it's opposite direction //and change the direction of extracting answer too if(oppoInd.find(iter) != oppoInd.end()){ iter = oppoInd[iter]; toRight = !toRight; //removing pointing to the parenthesis when changing iter index if(toRight) iter++; else iter--; } //extract the answers from the corresponding directions //until it reaches end or finds another parenthesis if(toRight){ while((iter < s.size()) && (oppoInd.find(iter) == oppoInd.end())) ans += s[iter++]; }else{ while((iter >= 0) && (oppoInd.find(iter) == oppoInd.end())) ans += s[iter--]; } } return ans; }
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 8 МЛН
Why Is He Unhappy…?
00:26
Alan Chikin Chow
Рет қаралды 54 МЛН
Advice from the Top 1% of Software Engineers
10:21
Kevin Naughton Jr.
Рет қаралды 3,3 МЛН
2751. Robot Collisions | Stack | Sorting | Not Hard 🫡
19:30
Aryan Mittal
Рет қаралды 6 М.
WhatsApp Messenger Runs Arbitrary Python Code
13:46
John Hammond
Рет қаралды 76 М.
The Algorithm Behind Spell Checkers
13:02
b001
Рет қаралды 409 М.
Coding Interviews Be Like
5:31
Nicholas T.
Рет қаралды 6 МЛН
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 8 МЛН