Valid Parentheses (LeetCode 20) | Full solution with visuals and animations | Stack Data Structure

preview_player
Показать описание

Chapters:
00:00 - Intro
00:52 - Problem Statement
03:08 - Understand valid parentheses
06:43 - Using stacks for efficiency
11:21 - Dry-run of Code
13:45 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#leetcode #programming #interview
Рекомендации по теме
Комментарии
Автор

Love You Sir, Got A Internship. 6 months of struggle. Got Pass my DSA test. Thanks.

arslanmuhammad
Автор

your explanation sticks to the brain, please continue the good work

toheebalawode
Автор

By Watching Your Videos now. I solved problems in efficient complexity. Thanks.

arslanmuhammad
Автор

thanks, sir, really loved your CLEAR STEP by step explanations.

priyabratapadhi
Автор

Keep up the Great work Sir, Thank you

rawat
Автор

Thank you sir. im confused from 4 days

SanthoshaK-wb
Автор

Sir please make some video on design patterns …it will be helpful… and thanks for wonderful videos on DSA

mahalasakini
Автор

Very informative video… could you please make a DSA playlist from a scratch

Nexgenstory
Автор

hi nikhil, there is a line else which made me confused,
if(is.empty || stack.pop()!=c) why did you write the condition is.empty?? wont it be !is.empty() since if its empty, we are gonna be returning true??

tasniatahsin
Автор

Thank you! You’re awesome!
Can you please also upload a solution of Leetcode 200?

נויבןדוד-גר
Автор

sir can you do videos on solving contest problems every week

pinnapureddynithinreddy
Автор

sir When You are going to work on Graphs.

arslanmuhammad
Автор

Sir, Which Tree can I learn. I Know about BST and AVL. Can You guide me for More Trees.

arslanmuhammad
Автор

Can you please provide solution for Human Readable Time

kurapatisabitha
Автор

class Solution {
public boolean isValid(String s) {
//valid parentheses would mean that all types of opening parentheses are correctly matched with their corresponding closing parentheses, and they are properly nested within each other.
Stack<Character> stack = new Stack();
for(char par : s.toCharArray()){
if(par == '('){
stack.push(')');
}else if(par == '{'){
stack.push('}');
}else if(par == '['){
stack.push(']');
}else if(stack.pop() != par){ this code is also working, but i dont know why at last else if condition we want 2 condition to check. can any one explain

return false;
}

}
return stack.isEmpty();


}
}

SanthoshaK-wb
Автор

Hi Nikhil, Your solutions are amazing. But for this particular problem, I feel this can be done in a better way instead of complicating it with a stack data structure. Please find my solution which was advised to me in an interview at Apexon UK. I find the solution to be intuitive and very simple.


private static boolean isBalancedParanthesis(String s){
do
{
if(s.contains("()")) s = s.replace("()", "");
if(s.contains("[]")) s = s.replace("[]", "");
if(s.contains("{}")) s = s.replace("{}", "");
}while(s.contains("[\\W]+"));
if(s.length()>0) return false;
else return true;
}

jjoelthomas