Reverse Substrings Between Each Pair of Parentheses - Leetcode 1190 - Python

  Рет қаралды 9,384

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/reverse...
0:00 - Read the problem
0:47 - Drawing Explanation 1
8:02 - Coding Explanation 1
10:58 - Drawing Explanation 2
18:37 - Coding Explanation 2
leetcode 1190
#neetcode #leetcode #python

Пікірлер: 39
@juanmacias5922
@juanmacias5922 24 күн бұрын
1:30 NeetCode loves us all, confirmed.
@harshkhandelwal6998
@harshkhandelwal6998 24 күн бұрын
Dude, i would have never come up with that second solution in my wildest dreams
@user-vk6ov4it8q
@user-vk6ov4it8q 24 күн бұрын
I actually thought the optimal sol but wasnt confident if i will code that properly. Nice Explanation NEET
@coolsai
@coolsai 23 күн бұрын
Thanks for the second solution Similar to you I also got first one crt !
@MP-ny3ep
@MP-ny3ep 24 күн бұрын
I was having a hard time understanding the O(n) time approach. You explained it so well. Thank you !
@EbrahemDroobi
@EbrahemDroobi 20 күн бұрын
Thanks for the awesome explanation I was very close to coming up with the linear time solution on my first try, But I got stuck on the two indexes approach until I ran out of time for solving the question. I then found your video online and realized how close I was if only I thought of creating a pair using a stack rather than stick to the two pointers approach. Thanks for the informative and amazing video NeetCode!
@ABC-op2nz
@ABC-op2nz 21 күн бұрын
The linear solution literally blew my mind....I think the harder part is to turn observation into an algorithm because I noticed the alternating pattern but I could not deduce how one pointer could just write the solution if you give it the right pivot points and jumps
@tuandino6990
@tuandino6990 24 күн бұрын
Nah im happy with my n2 solution, never could have come up with that linear solution
@chien-yuyeh9386
@chien-yuyeh9386 24 күн бұрын
Thanks for sharing!🎉
@UzairAhmed-gn5su
@UzairAhmed-gn5su 23 күн бұрын
the man who came wtih approach two he is a genius Wooow.Kudos
@wonderweebwoman
@wonderweebwoman 23 күн бұрын
Really cool solution, the second one!
@vijethkashyap151
@vijethkashyap151 23 күн бұрын
BEAUTIFUL!
@Igoy_05
@Igoy_05 23 күн бұрын
We need Dice roll simulation problem (Hard).
@shibainu9969
@shibainu9969 24 күн бұрын
Great video! Are there other leetcode problems that we can apply the second wormhole solution?
@shridhanushreddydappili7371
@shridhanushreddydappili7371 23 күн бұрын
I can't imagine , I actually though of the same 2nd method just as he said after banging my head for 40 mins
@user-ch9ln2ne2g
@user-ch9ln2ne2g 24 күн бұрын
I had solved the problem in the same way as the 1st approach but it didn't beat that many people 😅
@ahmedelhadary1899
@ahmedelhadary1899 24 күн бұрын
thanks for that great video, I have one question which is should I solve leetcode problems after finishing each topic (I mean solving problems on each specific topic) or should I wait until I finish the full DSA roadmap of whatever course I'm taking then start solving problems on the full DSA?
@deepaksingh7042
@deepaksingh7042 23 күн бұрын
SIMPLE CODE: With same intuition , since the characters in even numbered paranthesis will not get reversed and the characters in odd numbered will get reversed. We can simply use 2 pointers (start=0 and end=N-1) for the result array which will have same size as original array. Then do the following - 1. Iterate the original array using "current" pointer starting from index 0. 2. Also maintain an integer variable "count" which will keep track of the count of paranthesis in which our "current" pointer lies. If we encounter '(' then do ++count, and if we encounter ')' then do --count. 2. If current character lies in even numbered paranthesis (i.e. when "count" is even) then write that character at "start" position in result array and move "start" to next position. 3. If current character lies in odd numbered paranthesis (i.e. when "count" is odd) then write that character at "end" position in result array and move "end" one position backward.
@user-fx5lk6dy3m
@user-fx5lk6dy3m 23 күн бұрын
its wrong
@freecourseplatformenglish2829
@freecourseplatformenglish2829 23 күн бұрын
Although I came up with O(n) solution initially and failed to really code it up. I am settling for O(n^2) solution for being intuitive and that what I can actually code up during interview.
@karthik_sama
@karthik_sama 23 күн бұрын
This was fun
@sojwalgosavi4406
@sojwalgosavi4406 23 күн бұрын
kinda had the intution for second algo but could not code
@Sulerhy
@Sulerhy 24 күн бұрын
GODLIKE
@samarthjain5015
@samarthjain5015 24 күн бұрын
i love u 2
@gul9055
@gul9055 23 күн бұрын
I was so close. 😂
@jagrutitiwari2551
@jagrutitiwari2551 24 күн бұрын
I have sent you a LinkedIn request too.
@krr4k3n96
@krr4k3n96 23 күн бұрын
This exact one in C++... class Solution { public: string reverseParentheses(string s) { int n = s.length(); unordered_map mp; stack st; for (int i = 0; i < n; i++) { if (s[i] == '(') st.push(i); else if (s[i] == ')') { int j = st.top(); st.pop(); mp[i] = j; mp[j] = i; } } int i = 0; int dir = 1; string ans = ""; while (i < n) { if (s[i] == '(' || s[i] == ')') { i = mp[i]; dir = -1 * dir; } else { ans += s[i]; } i += dir; } return ans; } }; ☺
@MohanRam-mq2pk
@MohanRam-mq2pk 24 күн бұрын
I got the intuition on O(n) but I couldn't able to code it up... I don't know where I'm lacking in...
@PiyushYadav-pl9jm
@PiyushYadav-pl9jm 23 күн бұрын
waiting for the course on python
@AchintBhat
@AchintBhat 23 күн бұрын
kzfaq.info/get/bejne/qZl7m9SBz6i0kYU.htmlsi=b6w07rsbGdAf7A1b
@MeowsStore
@MeowsStore 24 күн бұрын
i'm second 😅 can i have a connect from you on linkedin
@beinghappy9223
@beinghappy9223 21 күн бұрын
Parentehsis problems means stack:
@fabricio5p
@fabricio5p 23 күн бұрын
i love you
@dossymzhankudaibergenov8193
@dossymzhankudaibergenov8193 24 күн бұрын
I solved it in same way as in 394.decode string
@Kabilan-v-143
@Kabilan-v-143 23 күн бұрын
"a(bcdefghijkl(mno)p)q" can any one explain this example
@lemons.3018
@lemons.3018 24 күн бұрын
I'm first
@TheSilentLooters
@TheSilentLooters 24 күн бұрын
my solution Runtime 28ms Beats 93.43% Memory 16.50MB Beats 81.94%
@gangeypatel624
@gangeypatel624 24 күн бұрын
lol I am early
@PiyushYadav-pl9jm
@PiyushYadav-pl9jm 23 күн бұрын
who tf actually came up with the second approach?
Maximum Score From Removing Substrings - Leetcode 1717 - Python
22:25
No empty
00:35
Mamasoboliha
Рет қаралды 10 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 52 МЛН
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 13 МЛН
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 394 М.
Why The Windows Phone Failed
24:08
Apple Explained
Рет қаралды 119 М.
Water powered timers hidden in public restrooms
13:12
Steve Mould
Рет қаралды 721 М.
How I Approach a New Leetcode Problem (live problem solving)
25:31
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 595 М.
How principled coders outperform the competition
11:11
Coderized
Рет қаралды 1,6 МЛН
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 839 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 153 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 287 М.
10 Math Concepts for Programmers
9:32
Fireship
Рет қаралды 1,8 МЛН
My iPhone 15 pro max 😱🫣😂
0:21
Nadir Show
Рет қаралды 1,4 МЛН
Лучший браузер!
0:27
Honey Montana
Рет қаралды 1 МЛН
Vision Pro наконец-то доработали! Но не Apple!
0:40
ÉЖИ АКСЁНОВ
Рет қаралды 88 М.
تجربة أغرب توصيلة شحن ضد القطع تماما
0:56
صدام العزي
Рет қаралды 63 МЛН