Parenthesis Checker | Valid Parentheses Leetcode | Balanced Parentheses Hackerrank | DSAOne #43
ฝัง
- เผยแพร่เมื่อ 26 ส.ค. 2024
- Hey guys, In this video, We're going to solve another very famous Interview Problem called - Parentheses Matching Problem.
code: www.geeksforge...
Practice questions: www.interviewb...
🥳 Join our Telegram Community:
Telegram channel: telegram.me/re...
Telegram group: telegram.me/ds...
🚀 Follow me on:
Instagram: / anuj.kumar.sharma
Linkedin: / sharma-kumar-anuj
Twitter: / realanujbhaiya
💸 Use coupon code ANUJBHAIYA on GeeksforGeeks to avail discounts on courses!
📚 Complete DSA Playlist: • DSA-One Course - The C...
Complete Android Development Playlist: • Android Development Tu...
Hashtags:
#anujbhaiya #dsaone
Ignore these tags:
parenthesis checker
valid parentheses
anuj bhaiya
valid parentheses leetcode
valid parentheses leetcode java
balanced parentheses hackerrank solution
balanced parenthesis
balanced paranthesis
balanced parentheses
longest valid parentheses
parentheses
valid parenthesis
valid paranthesis
balanced brackets
generate parentheses leetcode
minimum swaps for bracket balancing
sherlock and parentheses solution
stack in java
valid substring
20. valid parentheses
stack dsa
balanced parentheses problem
dsa in java
generate parentheses
minimum remove to make valid parentheses
remove invalid parentheses
parentheses and brackets
stack
stack in dsa
stack questions
stacks in java
valid parentheses leetcode c++
balanced brackets hackerrank solution
create a program to return array of all balanced parenthesis.
dense bracket sequence solution
leetcode valid parentheses
stack data structure
stack in data structure
)
anuj bhaiya dsa
anuj bhaiya java
apna college
boolean parenthesization
check for a matching contact in your org
create a program to return array of all balanced parenthesis
expression contains redundant bracket or not
generate parenthesis
leetcode 20
parenthesis
stack java
stack problems
time complexity analysis
valid parentheses java
valid parentheses leetcode python
2116. check if a parentheses string can be valid
In opening(char c) method it must be checked by double equals to ==, not by single assignment operator.
right
you are amazing ....! and few days before i saw your teaching technique its amazing after watching your video i feel very much confident and concentrate more to study. Thank you a lot for making this kind of videos.
Your coding logic is very strong 💪.
Literally i am searching for this problem now and I got suggestion of these vodio
Amazon mai job karne ke liye bohot papad bel naa padta hai...lekin aap chor diya isiliye ki aap apna Commitment pura kar sako .....bohot bura laga 😒you are great Anuj bhayia ❤️🙏
Sir I'm getting error as bad operand types for binary operator '||' & bad operand types for binary operator '&&' for this code
From now on I will definitely like your every video to support you as you have done same for all of us 🔥❤️
BHIYA......YOU ARE THE BEST TEACHER EVER ...WE WILL ALWAYS TRUST YOU AND ALWAYS BE SUPPORTIVE OF YOUR BEAUTIFUL JOURNEY ......WE LOVE YOU ANUJ BHIYA...AB THO AAPKE UPPER RESPECT AUR BHED GAYA HAIN MERA.....YOU ARE JUST AMAZING ...YOU NOT ONLY GUIDE ME..BUT INSPIRE ME A LOT BHIYA. I WANT TO BECOME LIKE YOU BHIYAA...😍❤🧡 YOUR JOURNEY IS VERY MUCH INSPIRATIONAL TO US ...FROM SUPER 30 TO AMAZON ..AND A PRO-TH-camR..AND WHAT NOT.....MORE OVER YOU ARE THE BEST CREATION...THANK YOU SO MUCH FOR YOUR EFFORTS TOWARDS US....AND MAKING OUR LIVES EASY AND NOT LETTING US FACE THE SAME STRUGGLE WHICH YOU FACED ...THERE'S NO ONE LIKE YOU!!!!... I AM 2 nd YEAR STUDENT AND I AM SO HAPPY THAT I CAUGHT YOU AT RIGHT TIME. THE WAY YOU EXPLAIN EACH AND EVERYTHING IN DETAIL ...WITH YOUR BEAUTIFUL SMILE ON YOUR FACE ...KEEPS PUSHING ME AHEAD ...TO WORK MORE AND HARDER ON IT......!! I KNOW I CAN DO IT ....ALL BECAUSE OF YOU...🧡🙏🙏🙏🙏 YOU ARE MAKING THIS TH-cam PLATFORM MORE RICHER ... YOU ARE THE BEST.....WE WILL KILL IT...
Respect to you brother. Keep up the good work 👏
Exceptional explanation 👏👏👏
No words for your compliments 🙇🙇🤗
i solved it few days ago in hackerrank
thank you bhaiya
Thanks a lot for the question sir
Thank you
we can also use the logic we use in palindrome, taking two pointers, return false if not match etc. And by this was we didn't use the space. GG
Bhaiya isme se konse algo imp hai aur konse imp nahi hai from graph
mtlb konse algo must do type hai
1. bellman ford
2. Floyd warshall
3. traveling salesman
4. flood fill algo
5. graph coloring
6. snake and game
7. tarjans algo
8. kosaraju algo
9. bridge in graph
10. articulate point
Awesome brother!! So neat 👍
your explanation is really great bhaiya. if possible ek dsa series (leetcode k questions) javascript me karao plz. I know javascript only. and javascript me dsa koi karata hi nhi.
bhaiya kya aap block chain managment pe tutorial bana skte h kya?
we need it
Well explained!!! 😊
You told on this video that we will see what happened when there are other characters alongwith brackets but maybe you missed. Please tell me how to deal with this?
//add this line before for loop
String valid = "({[]})";
//inside loop
char curr = str.charAt(i);
if(valid.indexOf(curr) == -1) {
//you can either "return false;" or
//you can ignore the character with "continue;"
//you can also use both, ex: when the character is number or operator you can ignore
//else you can return false
//depending on the problem statement
}
We can also use two increment operator count1 and count2 for the opening and closing parenthesis and atlast subtract both and if the value is zero string is valid else invalid
This approach will fail for cases like this:
)))(((
@@AnujBhaiya hats off u bhaiya ur programming logic is excellent 🙏🙏🙏
Awesome 🔥🔥🔥
Here we go again
i found this vdo really helpful🌻🌻
Please explain differences between below two:
"{ [ ] }" & "( [ ) ]"
Here both have closing so why first one is true and second is false ?
Hi, the opening and closing brackets should complement each other. Therefore, ( for ), [ for ] and { for }.
I hope you understood.
I had the same doubt, of the input string is ((]]{{[[}})).... Will this program work? Please let me know. Thanks!
Awesome video sir, really helpful
Great!!
amazing
acha pahele string ka size agar odd hua toh return false kar dena sahi hoga toh ?
Thank you so much sir
Nice explanation bhaiya❤❤
Thank you bhaijaan 🌟🌟🌟🌟🌟
@Anuj Bhaiya , Small enhancement... Can we add a condition as we know that if str.length() is odd then return false, as odd no. of brackets can't have its matches.
No. Because order also matters
@@RahulVerma-on7op Yes but if its odd we ll save so much of time & memory in returning output to user, it is just one efficient condition
if length is even: above logics thought in video would come, but if its odd straight away we can return false.
class Solution { //Function to check if brackets are balanced or not. static boolean ispar(String x) { Stack st=new Stack(); st.push('a'); for(int i=0;i
I have been following this amazing course!
I just want to know that is there any platform where I can save all these codes and also the problems I solved in an organized way so that I can access them easily in future for revision and reference.
Anuj bhaya we can also solve this problem using Catalan numbers also right
Bhaiya .. when the string length is even then it's true and when it's odd it's false
What about this case bro:- "(}{)"
@@jeffkirchoff14 first the opening should come na!!
First characters in the string should be open braces follwed by closed braces.. the thing is matching braces are there or not.. for example ((}} (this should be false ) I just proposed a condition of odd even it's not the full code
I doesn't mean that it's gonna be true every time when it's even
@@jeffkirchoff14 hmm... Right
Bhai , Python ka Ek Series Banao With 150 Top Interview Problems. Which is not available in youtube in HIndi. Pura Desi bhasa mein.
thanks bhaiya
Can i write the same code for the question Write a program in ‘C’ to check for balanced parenthesis in
an expression using stack.
Thanks big bro 👍👍
@anuj bhaiya Bhaiya,can u please also provide the list of most important questions related to that topic which u covered in your video so that we can do more practice by ourselves,bcz over internet there are lots of questions and I am confused that time at that which question I have to solve .so It's request to u bhaiya ,if it will be possible please do for us🙏🙏🙏🙏
Bhaiyya Catalan numbers theory samjha dijiyega
@Anujbhaiya abhi course complete hone me kitna time lagega....
May be it's personal but shashank mishra said that amazon never asked you to leave , bhaiya please clear us on this , is he lying ?
can we do it by two pointer method , like one from 0th index and one from nth index and keep comparing till we reach middle or we don't find right pair
no not for this {}() case my bad
Pls provide code in python also
Open parentheses ko pop kyu jab closing parentheses aata hai to ?????
Have three variable br1=0, br2=0, br3=0. Whenever opening bracket do respective br++ ,
When closing bracket do respective br--
At end check all br==0 then balanced else unbalanced.
This approach will fail for cases like these:
)(][}{
@@anujkumarsharma1013 will add an additional condition if br1= 0 and facing a closed bracket break the loop saying unbalanced...🙂
Perfect then 🙌
@@harshitshukla4532 I liked this approach its very simple and efficient no need of stack also :D
public static boolean checkBalance(String s) {
int br1=0,br2=0,br3=0;
for(int i=0;i
thanks bhayi
Bhaiya please make a video on """how to learn Javascript"""
Android development with kotlin course kb se aayega
Mujhe English bilkul nhi aati, aur me bahot jyada introvert hu,
Lekin main coding me bohot achha hu, ye problem main bina stack ke 3 line of code me kr liya.
Mujhe job nhi mil rhi, bolate time me atakta hu, mujhe 1 question ke bad hi interview se bahar nikal dete hai.
Mujhe kuch samajh nhi aa rha,
Job nhi hai aur maa bimar hai
What If we have a problem like this “}}]]))” this code will also return true in that case because stack will be empty only ?
bhaiya meko na eak problem h
main problem ko smjh kr uske solutions mind me calculte ke leta hu ki aaise aaise hona chahiye
pr na code nhi likh pata
kya kru!!
Great
Sir can you please make how we can make hanoi game in any language but my preferred language is PHP if you can make this video then it can help to understand.
Add more questions like this🔥🔥
what if we having an input like " } ( ) { " .Based on your algorithm output is false right?.. but here they are balanced or not .In my point of view they have a pair of { } ( ).Whether my question is reachable ?..
as parenthesis they must have a opening bracket before closing
Hi @anuj bhaiya , can below be considered as Balanced String
{}[(]){}
according to me no its not
while writing the same code on leetcode , its showing so much errors
Bhaiya, should I take a maths course for CP
No
First First comment to thk h Like bhe karte jao yrr video, sir itne mhnat kar rahe h or aap like bhe nai kar rahe
Can anyone please confirm whether it is valid or not?
String str = "))XYZ(("
lot's of love to Anuj bhaiya and Love Babbar ❤️❤️❤️
2nd Time...
❣❤
beacause of this question i fail in my interview
Is college syllabus enough to crack top MNC?
why not do this problem by placing a pointer at the starting of the string and one at the end and then bringing them towards the centre by iterations and comparing them at each iteration. if they don't match at any instance return false. this will take constant space and O(n) time
suppose you have string like this
()(){{}()}
then in this case start and end operator will not match and give us false but actually it,s true.
First
Anuj bhaiya.. please complete this DSA one till December 2021.. I will be passing out in 2022. I am fully dependent on this course.
❤❤❤❤
Left Amazon 🙄
👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻
Leetcode program without error
class Solution {
public boolean isopening (char c){
return c =='(' || c == '{' || c == '[' ;
}
public boolean ismatching (char a,char b){
return (a =='(' && b ==')') || (a =='{' && b == '}') || (a =='[' && b == ']');
}
public boolean isValid(String s) {
Stack str = new Stack();
for ( int i = 0; i< s.length() ;i++){
char cur = s.charAt(i);
if( isopening (cur)){
str.push (cur);
}
else {
if(str.isEmpty ()) {
return false ;
}
else if (!ismatching (str.peek() ,cur)) {
return false;
}
else{
str.pop();
}
}
}
return str.isEmpty();
}
}
Helpful 👍
10th comment
1st year students
😍😍❣♥
Python Solution:
def isValid(self, s: str) -> bool:
Que=[]
Map={"(":")","[":"]","{":"}"}
for i in s:
if(i in Map):
Que.append(i)
else:
if(len(Que)!=0 and Que[-1] in Map and Map[Que[-1]]==i):
Que.pop()
else:
return False
return len(Que)==0
#Runtime: 34 ms, faster than 31.19% of Python3 online submissions for Valid Parentheses.
#Memory Usage: 14.3 MB, less than 65.11% of Python3 online submissions for Valid Parentheses.
import java.util.*;
public class ValidParenthesis{
static boolean isParenthesisMatching(String str){
Stack s=new Stack();
for(int i=0; i
Can you please write it for c++
thankyou for this code
Great
First