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

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.พ. 2025

ความคิดเห็น • 65

  • @arslanmuhammad4190
    @arslanmuhammad4190 ปีที่แล้ว +23

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว +4

      all the very best...congrats 😄

    • @adityasingh2883
      @adityasingh2883 8 หลายเดือนก่อน +1

      Bhai mujhe guide kardo yaar konsi company main internship mili or kaise mili kya criteria tha?

    • @ashishkarthik2817
      @ashishkarthik2817 6 หลายเดือนก่อน

      Hey bro can u tell how and what all did u practice

  • @toheebalawode1634
    @toheebalawode1634 5 หลายเดือนก่อน

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

  • @arslanmuhammad4190
    @arslanmuhammad4190 ปีที่แล้ว +1

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      Excellent!

  • @ishimwezachee2179
    @ishimwezachee2179 10 หลายเดือนก่อน +2

    You are the best for sure

  • @priyabratapadhi2421
    @priyabratapadhi2421 8 หลายเดือนก่อน +1

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

  • @rawat7203
    @rawat7203 ปีที่แล้ว +2

    Keep up the Great work Sir, Thank you

  • @SanthoshaK-w5b
    @SanthoshaK-w5b 11 หลายเดือนก่อน +1

    Thank you sir. im confused from 4 days

  • @sarthakmahadik9760
    @sarthakmahadik9760 ปีที่แล้ว +1

    Very informative . Love you Man

  • @ashmita_shrivastava
    @ashmita_shrivastava 5 หลายเดือนก่อน

    best solution till date

  • @contentorwhat6452
    @contentorwhat6452 4 หลายเดือนก่อน

    Best Explanation Sir!!!!

  • @MdShamuel
    @MdShamuel ปีที่แล้ว +2

    Amazing Bro . keep it up💘.

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      Thanks 🔥

  • @tasniatahsin8637
    @tasniatahsin8637 ปีที่แล้ว +2

    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??

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      We are doing this to check if the stack becomes empty without matching all the brackets.

    • @rohithbhandari7836
      @rohithbhandari7836 11 หลายเดือนก่อน

      ​@@nikoo28 That is only possible when input contains numbers or letters Is not input always contains parenthesis or brackets ?

    • @nikoo28
      @nikoo28  11 หลายเดือนก่อน

      Check the problem constraints

    • @AniketVBhukne
      @AniketVBhukne 5 หลายเดือนก่อน +1

      What if string starts with close bracket like "]()" it will try to pop empty stack and will throw error so that stack.isEmpty() Condition is there

  • @AbdulRajak-x8v
    @AbdulRajak-x8v 14 วันที่ผ่านมา

    All are fantastic explanation but am not het why he use stack.isEmpty() How Empty will be false empty stack means all are removed successfully am right if anyone know this kindly clarify me

  • @mahalasakini5045
    @mahalasakini5045 ปีที่แล้ว

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว +2

      design patterns, system design, graphs...these are the next series of videos in my pipeline..stay tuned!!

  • @FR0ZING
    @FR0ZING 9 หลายเดือนก่อน +1

    thank you so much 🙏🙏🙏

  • @Nexgenstory
    @Nexgenstory ปีที่แล้ว +1

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      what kind of videos are you looking for? I have videos on stacks/queue, other data structures...

  • @appikeeru5785
    @appikeeru5785 6 หลายเดือนก่อน

    Sir very clear explanation 👌

  • @nandanihada4461
    @nandanihada4461 6 หลายเดือนก่อน

    great explanation😄

  • @pinnapureddynithinreddy4805
    @pinnapureddynithinreddy4805 ปีที่แล้ว +1

    sir can you do videos on solving contest problems every week

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      I post a new video every week :)

  • @jashanjotbedi1796
    @jashanjotbedi1796 11 หลายเดือนก่อน

    Explaination is at par level .

  • @נויבןדוד-ג5ר
    @נויבןדוד-ג5ר ปีที่แล้ว

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

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      yes, that is a very popular problem indeed. Will make a video soon

  • @subee128
    @subee128 ปีที่แล้ว +1

    Thanks

  • @arslanmuhammad4190
    @arslanmuhammad4190 ปีที่แล้ว +1

    sir When You are going to work on Graphs.

    • @nikoo28
      @nikoo28  ปีที่แล้ว +2

      very soon. My next week video will be on introduction to graphs

    • @arslanmuhammad4190
      @arslanmuhammad4190 ปีที่แล้ว

      @@nikoo28 Thanks Sir

    • @nikoo28
      @nikoo28  ปีที่แล้ว

      The complete playlist on graphs is now available: th-cam.com/play/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn.html

  • @parthmodi2028
    @parthmodi2028 ปีที่แล้ว

    Greak Work Sir

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      Thanks

    • @MrShrane
      @MrShrane 8 หลายเดือนก่อน

      @@nikoo28 Sir please answer my one doubt , are we not required to return true?? why was there no returning of true? else how will we get it

    • @MrShrane
      @MrShrane 8 หลายเดือนก่อน

      ohh got it ,thanks sir understood the last part

  • @kurapatisabitha
    @kurapatisabitha 9 หลายเดือนก่อน

    Can you please provide solution for Human Readable Time

    • @nikoo28
      @nikoo28  9 หลายเดือนก่อน

      Can you provide me a link to the problem?

  • @arslanmuhammad4190
    @arslanmuhammad4190 ปีที่แล้ว

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

    • @abhi_coder6
      @abhi_coder6 ปีที่แล้ว +2

      Bhai kafi h yaar bas rulayega kya itna hi karle aur question practice kar bas aur kuch nhi mostly tujhe bst pe bt pe bhi sawal milega avl rare h

    • @nikoo28
      @nikoo28  ปีที่แล้ว +3

      exactly, you don't need so much. BST and binary trees are usually enough.

    • @arslanmuhammad4190
      @arslanmuhammad4190 ปีที่แล้ว +1

      sir Please I know about BST and AVL but What are other Binary trees.

    • @arslanmuhammad4190
      @arslanmuhammad4190 ปีที่แล้ว

      @@abhi_coder6 yaar to sai khta ha lekin smj nai a rai or konsay binary trees.

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      @@arslanmuhammad4190 solve more problems on binary trees, just understanding the concept is not enough. Try to find the lowest common ancestor, least paths, backtracking in trees etc.

  • @SanthoshaK-w5b
    @SanthoshaK-w5b 11 หลายเดือนก่อน +1

    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 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();
    }
    }

    • @ramanarao4646
      @ramanarao4646 7 หลายเดือนก่อน

      @user-ei3ng5kt4n check for this input String s =")";

    • @AniketVBhukne
      @AniketVBhukne 5 หลายเดือนก่อน +1

      Here problem is what if string stars with close bracket? Like this "]()[]" it will not push any charecter to stack but will try to pop the empty stack which will throw error so you must add isEmpty() Condition to avoid error

  • @ssss22144
    @ssss22144 3 หลายเดือนก่อน

  • @jjoelthomas
    @jjoelthomas ปีที่แล้ว

    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;
    }

    • @nikoo28
      @nikoo28  ปีที่แล้ว +1

      that works as well, but I was also trying to give an idea about how to solve mathematical expressions also. :)
      You are also relying on "contains" functionality.

    • @jjoelthomas
      @jjoelthomas ปีที่แล้ว

      @nikoo28 I don't mean to discredit you. Because I learn a lot from you. And this solution I posted just in case someone's looking for an easy solution. Anyway your videos are all amazing and you are really doing a great work

    • @vishalrai6027
      @vishalrai6027 5 หลายเดือนก่อน

      @@jjoelthomas you have to tell the interviewer that contains and replace function are costly. makes whole program as O(n^2)

  • @motivationalmusic3721
    @motivationalmusic3721 22 วันที่ผ่านมา

    i got the algoirthm

  • @kinderhero8897
    @kinderhero8897 6 หลายเดือนก่อน

    классная кофта со спайдером

  • @RoshanSingh-kj4fy
    @RoshanSingh-kj4fy หลายเดือนก่อน

    Tw