nice to see that our code is almost same: class Solution: def maxDepth(self, s: str) -> int: ans = 0 left, right = 0, 0 for i in s: if i == "(": left += 1 elif i == ")": right += 1 ans = max(ans, left - right) return ans
@@shitluna50kgonedogegogogo87 wow you have complicated it so much and are using a stack as well , so I guess SC is O(n) as well and you are solving for all kinds of brackets but if you had seen the question carefully, then you would have known that it contained only () this kind of brackets and there is no need of using any extra space as well, so unnecessarily complicating things is not a good way to solve any question bro, hope you take it positively
wish every daily was this easy
Then we wouldn't learn anything!
if you only do what you can do then you will never be more than you are now (-shifu btw)
Man this is a really straightforward problem. They should have made it so that the parenthesis might not have been valid to make it more fun
1111. Maximum Nesting Depth of Two Valid Parentheses Strings Enjoy
then it wouldnt be an easy.
Ty man will check it out@@ombhamare623
true
@@chrischika7026
this is one of those problems where trying to read the description is harder than solving the problem itself.
Your explanation skills are insane. Thank you so much. As you started explaining the problem, it leads me to the solution automatically
i was about to search this problem and youtube recommended it on homepage.
they're in your walls
Anything about daily LC 2444. Count Subarrays With Fixed Bounds ?
Ye, I wanted to see that too
great job navdeep congratulations on the coin for a one day streak!
I've always implemented this problem with the stack DS which made the space complexity O(n)
Nicely explained 💯
same :D
Probably the easiest leetcode problem ive seen so far.
The singular of "parentheses" is "parenthesis" not "parenthesee"
Imagine big tech asking this question
Solved it!!
why didnt u uploaded solution videos for the past few days?
I uploaded videos for them in the past. You can usually find them by searching TH-cam
I think the code will fail for (() this will give the output as 2 but it is not a valid parenthesis it should give 0 right?
It is given that the i/p is a vps.
This was easy, but that description is just asinine like wtf was bro yapping about
i didnt even bother reading allat
nice to see that our code is almost same:
class Solution:
def maxDepth(self, s: str) -> int:
ans = 0
left, right = 0, 0
for i in s:
if i == "(":
left += 1
elif i == ")":
right += 1
ans = max(ans, left - right)
return ans
Interesting approach, although you run max more often than in other solutions
@@neks2081 yeah that might take extra time
func max_depth(str string) int {
stack := []string{}
mapping := make(map[string]string)
mapping["("] = ")"
mapping["["] = "]"
mapping["{"] = "}"
rev_mapping := make(map[string]string)
cur_count := 1
max_count := 1
for key := range mapping {
rev_mapping[mapping[key]] = key
}
for i := 0; i < len(str); i++ {
char := string(str[i])
if mapping[char] != "" {
stack = append(stack, char)
cur_count++
} else if rev_mapping[char] != "" {
ulta := rev_mapping[char]
max_count = max(max_count, cur_count)
cur_count = 0
if stack[len(stack)-1] != ulta {
return -1
} else {
stack = stack[:len(stack)-1]
}
} else {
continue
}
}
if len(stack) == 0 {
return max_count
}
return -1
}
@@shitluna50kgonedogegogogo87 wow you have complicated it so much and are using a stack as well , so I guess SC is O(n) as well and you are solving for all kinds of brackets but if you had seen the question carefully, then you would have known that it contained only () this kind of brackets and there is no need of using any extra space as well, so unnecessarily complicating things is not a good way to solve any question bro, hope you take it positively
@@BurhanAijaz while solving, i am also checking wheather the brackets are valid
Hello my crush