Stack - Data Structures & Algorithms Tutorial In Python #7

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ธ.ค. 2024

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

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

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

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

    This series gotta be super hit in future

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

      I'm watching it from the future and I can tell you is a super hit for me!

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

      @@daniel280187 no I'm watching from future and it is no where near super hit considering the Indian origin. Like if even 0.5 percent indian started watching this, the views will be in millions. If ur not indian then u might have trouble understanding that 70-80 percent graduates are engineers and learning some coding language and even on those python is on top. So yeah it should have atleast 1 million views man.

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

      @@rheumaticharm9551 I think I'm from future and these tutorials are masterclass hit now !!

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

      @@rheumaticharm9551 okay but what about now?

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

      No. I'm frm the future🚶

  • @jccrunk4real
    @jccrunk4real ปีที่แล้ว +7

    This is literally the best explanation of a stack I have ever seen. I'm someone who dreads data structures and algorithms but after watching this video, I'm actually excited to watch the rest of your DS tutorials. Thank you!

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

    Absolutely hilarious bit at the end. I couldn't stop laughing! 😂 :
    "If you look at the solution without first solving the problem, it's going to download the covid-19 virus to your computer".

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

      @@IITVital kya bol raha hai bhai? IIT ka naam badnaam karega kya

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

    The way, you explain things, I love it. Most loving part is the exercises.

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

    You make some of the easiest to understand explanations for coding stuff that I have come across on the internet. Thank you so much!

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

    Thanks a lot, It helped me to understand the concept in python. Keep making such good contents. Here is the code of the exercise questions.
    solution 1:
    from collections import deque
    class stack:
    def __init__(self):
    self.container=deque()
    def push(self,val):
    self.container.append(val)
    def pop(self):
    return self.container.pop()
    def peek(self):
    return self.container[-1]
    def is_empty(self):
    return len(self.container)==0
    def size(self):
    return len(self.container)
    def reversestring(s):
    st=stack()
    for i in s:
    st.push(i)
    revstr=""
    while(st.size()!=0):
    revstr+=st.pop()
    return revstr
    print("this function is for reversing a string using stack")
    print(reversestring("hello my name is rajnish"))
    solution 2:
    from collections import deque
    class stack:
    def __init__(self):
    self.container=deque()
    def push(self,val):
    self.container.append(val)
    def pop(self):
    return self.container.pop()
    def peek(self):
    return self.container[-1]
    def is_empty(self):
    return len(self.container)==0
    def size(self):
    return len(self.container)
    def isbalanced(s):
    st=stack()
    flag=0
    ch=0
    for i in s:
    if i=="(" or i=="{" or i=="[":
    ch+=1
    st.push(i)
    if (i==")" and ch==0) or (i=="}" and ch==0) or (i=="]" and ch==0):
    flag=1
    break
    if i==")" or i=="}" or i=="]":
    x=st.pop()
    ch-=1
    if x=="(" and i!=")":
    flag=1
    break
    if x=="{" and i!="}":
    flag=1
    break
    if x=="[" and i!="]":
    flag=1
    break
    if flag==1:
    return "False"
    else:
    return "True"
    print(isbalanced("({a+b})"))
    print(isbalanced("))((a+b}{"))
    print(isbalanced("((a+b))"))
    print(isbalanced("))"))
    print(isbalanced("[a+b]*(x+2y)*{gg+kk}"))

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

    Data Structures became very interesting with your videos Thank You, sir!!

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

      Glad you like them!

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

    "Watch other data structures videos"
    I will for sure.
    At first I had curiosity. But now, this channel have my attention.

    • @ohno.6516
      @ohno.6516 3 ปีที่แล้ว +1

      Django unchained, nice

    • @TheSoulCrisis
      @TheSoulCrisis 3 ปีที่แล้ว

      lol nice

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

    Simplified way of explanation, I've been trying to find some resources for python dsa and this is the best. !!

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

    Read stacks & queues in 12th class,... but always wondered what its for... browser example really makes sense

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

    Diagram for Stack Implementation quick correction
    4:52 - Python Code Sample
    stk = deque()
    stk.append(5)
    stk.append(89) # correction 89 not 9
    stk.pop() # returns 89

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

      wow, thanks Glory for your keen observation.

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

    Second exercise item in this tutorial is a brilliant use of push & pops in stack....!
    Got the logic for similar set of questions in leetcode. Thank You.

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

    Your videos are amazing, you make learning Python much easier! Thankyou :)

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

    Thank you very much, for sharing knowledge for free!

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

    Thank you. You have a great way of explaining concepts . Codebasics for dummies :)

  • @ujjwalsingh3160
    @ujjwalsingh3160 3 ปีที่แล้ว

    just a random vdo i clicked nd this is what i got the diamond ,while i was looking for gold.....!!! you're the best sir.

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

      I am happy this was helpful to you.

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

    Covid virus cringe apart, this is a clean and concise video. Thanks!

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

      I am happy this was helpful to you.

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

    Thank you. This video help me to understand the subjet.

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

    thank you dear Sir! Your videos are easy to follow and they are very informative. Take care during outbreak

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

      Glad you like them!

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

    Also, if you inherited deque you wouldn't have to redefine some methods, such as pop, you could just reference the base class method. (I get that this tutorial wasn't about OOP)

  • @troymendoza1388
    @troymendoza1388 3 ปีที่แล้ว

    Thank you. This playlist have been very helpful. Keep up the great work!

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

    Covid 19 virus 😂, i felt like classroom immediately

  • @alkeshace6158
    @alkeshace6158 3 ปีที่แล้ว

    For interview and for oral, this is helpful. Thanks for the videos/

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

    simple and precise
    Thank you!

  • @narinpratap8790
    @narinpratap8790 3 ปีที่แล้ว

    Awesome content! It's great that you're able to squeeze in so much valuable information into a 13 minute video.
    Also, sorry if I sound pedantic here... but I believe the correct pronunciation of deque is "deck" (written in the documentation at 7:59).
    Thank you for the valuable content :D

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

      Narin thanks for informing about pronunciation. My english is not the best and I take your feedback positively. Thanks for teaching me that and I will use "deck" going forward :)

  • @kapildharmale319
    @kapildharmale319 2 ปีที่แล้ว

    so detailed, i like the exercises

  • @luciferkhusrao
    @luciferkhusrao 2 ปีที่แล้ว

    "Download COVID-19 virus". That was really funny 😂. But tutorial was awesome. 🤩🤩

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

    Super exercises 👍

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

    I implemented below short solution to the first exercise :
    from collections import deque
    def reverse_string(string):
    lst = []
    stack = deque(string)
    for i in string:
    lst.append(stack.pop())
    return ''.join(lst)
    print(reverse_string("We will conquere COVID-19"))
    >>> 91-DIVOC ereuqnoc lliw eW

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

    covid-19 on the PC good one :)

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

    There's so much in my head i need to remember and idk what any of it is for sometimes.

  • @khanhhoang3840
    @khanhhoang3840 3 ปีที่แล้ว

    It really helps me, Thank you so much!

  • @KARTHIKA-r2y
    @KARTHIKA-r2y 3 หลายเดือนก่อน +1

    without formatting stack object to str how are you printing by just giving its name sir?
    Without the __str__ I am getting memory address only!
    def __str__(self):
    return str(list(self.container))

    • @perfectcell1157
      @perfectcell1157 2 หลายเดือนก่อน

      It's probably because he is using jupyter notebook
      in your Stack class write the following:
      def print(self):
      for val in self.container:
      print(val)
      and if you want it to print it like a legitimate stack (first element at the bottom)
      reverse the self.container in the 'for' condition with reversed(self.container)
      now you can easily print the stack you have by simply calling the print() method
      eg.
      S = Stack()
      S.push(1)
      S.push(2)
      S.push(3)
      S.print()
      outputs:
      3
      2
      1
      hope this helped

  • @nyctophialicnid782
    @nyctophialicnid782 2 ปีที่แล้ว

    Hi Dhaval, I tried implemening the STACK using Linked list cause I was curious how the dequeue was working behind the scene so here is my solution for the 1st Exercise. Do have a look and if you have any suggestions then let me know..
    # Stack using Linked List
    class Node:
    def __init__(self, prev = None, data = None, next = None) -> None:
    self.prev = prev
    self.data = data
    self.next = next

    class Stack:
    def __init__(self) -> None:
    self.head = None
    self.top = None

    def push(self, data):
    if self.head == None:
    node = Node(None, data, None)
    self.head = node
    return
    itr = self.head

    while itr.next:
    itr = itr.next

    node = Node(itr, data, None)
    itr.next = node
    self.top = node

    def pop(self):
    # print(self.top.data)
    if self.head == None:
    return print("Stack is Empty")
    data = ''
    if self.top.prev is not None:
    data = self.top.data
    self.top.prev.next = None
    self.top = self.top.prev
    else:
    data = self.top.data
    self.head = None
    self.top = None
    return data
    def peek(self):
    if self.head == None:
    return print("Stack is Empty")
    return self.top.data
    def print(self):
    if self.head == None:
    return print("Stack is Empty")
    itr = self.head
    llstr = ''
    while itr:
    llstr += f"{ itr.data } => "
    itr = itr.next
    print(llstr)
    def size(self):
    count = 0
    itr = self.head
    while itr:
    count += 1
    itr = itr.next
    return count
    def reverse_string(string):
    s = Stack()
    for c in string:
    s.push(c)
    rstring = ''
    while s.size():
    rstring += s.pop()
    print(rstring)
    s.print()
    reverse_string("We will conquere COVID-19")

  • @Rajkumar-vc2pg
    @Rajkumar-vc2pg 3 ปีที่แล้ว

    some one told me coding people don't have humour and boring , then i showed them ur channel

  • @priyanshupurohit5431
    @priyanshupurohit5431 2 ปีที่แล้ว

    thankyou very much sir :)

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

    sir please make full tutorial on data structures along with algorithm using python with every detail please we newbie programmer need this . and a thanku to you sir for this video

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

    Thank you for another extremely useful video!
    I would like to present my approach on the second exercise. Please reach out and provide feedback for this implementation:
    from collections import deque
    class Stack:
    def __init__(self):
    self.container = deque()
    def push(self, val):
    self.container.append(val)
    def pop(self):
    return self.container.pop()
    def peek(self):
    return self.container[-1]
    def is_empty(self):
    return len(self.container)==0
    def size(self):
    return len(self.container)
    def reverse_string(a_string):
    s = Stack()
    for x in a_string:
    s.push(x)
    new_string = ''
    for y in range(s.size()):
    new_string += s.pop()
    return new_string
    def is_balanced(a_string):
    s = Stack()
    d = Stack()
    check = Stack()
    for char in a_string:
    if char in "{}[]()":
    s.push(char)
    for char in range(len(s.container)-1, -1, -1):
    d.push(s.container[char])
    #print(s.container)
    #print(d.container)
    if len(s.container) != 0 and len(s.container) % 2 == 0:
    mean = int(len(s.container)/2)
    for i in range(mean):
    check.push(s.container[i]+d.container[i])
    for set in check.container:
    if set not in ["[]","()","{}"]:
    c = False
    else:
    c = True
    return c
    print(is_balanced("({a+b})"))
    print(is_balanced("))((a+b}{"))
    print(is_balanced("((a+b))"))
    print(is_balanced("))"))
    print(is_balanced("[a+b]*(x+2y)*{gg+kk}"))

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

      Thanks for the answers veryvery helpfull

  • @SushantaKPani
    @SushantaKPani 2 ปีที่แล้ว

    4:58 in python code sample typo correction stk.append(89) instead of stk.append(9)

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

    Hey in the last exercise why did we returned stack.size()==0 can you explain

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

    Should this be episode #6?

    • @codebasics
      @codebasics  4 ปีที่แล้ว

      You are right. Updated the title. Thank you 😊

  • @mahdip.4674
    @mahdip.4674 2 ปีที่แล้ว +1

    can we search for max or min value in stack and make it O(1)?

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

    god lvl teaching,,pls expand the series more

  • @alrzhr
    @alrzhr 2 ปีที่แล้ว

    very helpful

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

    The answer is
    from collections import deque
    class Stack:
    def __init__(self):
    self.container = deque()
    def push(self, val):
    self.container.append(val)
    def pop(self):
    return self.container.pop()
    def peek(self):
    return self.container[-1]
    def is_empty(self):
    return len(self.container) == 0
    def size(self):
    return len(self.container)
    def reverse_string(s):
    stack = Stack()
    for ch in s:
    stack.push(ch)
    rstr = ''
    while stack.size()!=0:
    rstr += stack.pop()
    return rstr
    if __name__ == '__main__':
    print(reverse_string("We will conquere COVI-19"))
    print(reverse_string("I am the king"))

  • @kk420100
    @kk420100 9 หลายเดือนก่อน +2

    seriously what the heck! i was looking to download covid19 virus but instead downloaded a big fat python.😜

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

    great content ! how is memory management for deque? is it better than list

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

    Hello Sir, can you please create a video developing of project using only DSA ?

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

    Why is it that id(list) doesn't change even after append as list is basically a dynamic array?

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

    ***solution spoiler***: the use of dictionary in problem 2 was so smart!

  • @vishnupandey3390
    @vishnupandey3390 2 ปีที่แล้ว

    Solution 1
    class stack:
    def __init__(self):
    self.stack=deque()
    self.ans=""
    def insert(self,ele):
    self.stack.append(ele)
    def remove(self):
    self.stack.pop()
    def reverse_string(self):
    ele=self.stack.pop()
    self.ans+=ele
    if len(self.stack)!=0:
    return self.reverse_string()
    else:
    return self.ans
    from collections import deque
    s1=stack()
    s1.insert("0")
    s1.insert("1")
    s1.insert("2")
    s1.insert("3")
    s1.insert("4")
    print(s1.reverse_string())

  • @arijitdas1551
    @arijitdas1551 2 ปีที่แล้ว

    For the example of webbrowser back and forward button, why can't we use doubly linkedlist ?

  • @Heck-ed6sr
    @Heck-ed6sr 3 ปีที่แล้ว

    Can anyone explain to me how the memory storage/allocation of stacks work? Do they face similar issues with dynamic arrays (copying and paste each individual data one at a time to the new memory location)? Any help will be much appreciated! Thanks!

    • @vijitmalik8708
      @vijitmalik8708 3 ปีที่แล้ว

      stack is built using different data structures, In python as told in the video, if we use deque to implement it then it works as a doubly linked list so python memory allocation is similar to that of a linked list. watch again from 6:40

  • @Mohib3
    @Mohib3 3 ปีที่แล้ว

    in interviews we can use deque? Might be dumb question but im just now learning DS ALGO?

  • @rafeeka9871
    @rafeeka9871 4 ปีที่แล้ว

    i am so much grateful to you thank you very much for such clear and neat explanation

  • @nishantthakur3035
    @nishantthakur3035 4 ปีที่แล้ว

    class Check:
    def __init__(self):
    self.check = deque()
    def push(self,val):
    self.check.append(val)
    def is_paranthesis(self):
    para = ['{','}','(',')','[',']']
    for i in para:
    return self.check[-1].count(i)==1

  • @anjaneyatiwari4012
    @anjaneyatiwari4012 2 ปีที่แล้ว

    hye , can we implement stack in python without using in-build function like append and pop ??

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

    thank you so much

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

    can someone please explain this part of code from the solution:
    if ch==')' or ch=='}' or ch == ']':
    if stack.size()==0:
    return False
    if not is_match(ch,stack.pop()):
    return False
    return stack.size()==0

    • @aaravchandra3082
      @aaravchandra3082 4 ปีที่แล้ว

      Basically, you want to see that if u encounter either of the three brackets the top bracket on the stack should be its opening counterpart. I those two are the same then no False is set. In the end if no false is set and if last bracket is also processed ten return true.

    • @nishantthakur3035
      @nishantthakur3035 4 ปีที่แล้ว

      class Check:
      def __init__(self):
      self.check = deque()
      def push(self,val):
      self.check.append(val)
      def is_paranthesis(self):
      para = ['{','}','(',')','[',']']
      for i in para:
      return self.check[-1].count(i)==1

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

    Nice tutorial and it helped me a lot. Waiting for the next set of Data structure tutorials.

    • @codebasics
      @codebasics  4 ปีที่แล้ว

      Glad to hear that

  • @bhavanisankar8272
    @bhavanisankar8272 2 ปีที่แล้ว

    hi sir,How to print elements of stack

    • @somanyadav792
      @somanyadav792 2 ปีที่แล้ว

      See def show in the below code. It shows all the elements in the stack :)
      class Stack():
      def __init__(self):
      self.container = deque()
      def push(self,val):
      self.container.append(val)
      def pop(self):
      return self.container.pop()
      def peek(self):
      return self.container[-1]
      def is_empty(self):
      return len(self.container)==0
      def size(self):
      return len(self.container)
      def show(self):
      return self.container

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

    Your theoretical explanation is top notch, but explanation of code sure needs some improvement beginner with the less knowledge have difficulty in understanding

  • @muhammadzakiahmad8069
    @muhammadzakiahmad8069 2 ปีที่แล้ว

    If one is not able to solve the second exercise on his/her own this means his/her logical skills are weak? I heard a youtuber saying that if you know the basic operations of stacks then you should be able to do it.

  • @MuhammadAli-bn4ju
    @MuhammadAli-bn4ju 2 ปีที่แล้ว

    in python: when you add new elements to a list its id address will not change! and I know that python list has no max size. so, if that true, is that mean it's no problem using it as a stack?

    • @vishnupandey3390
      @vishnupandey3390 2 ปีที่แล้ว

      no watch the portion of this video th-cam.com/video/p_9t8uhXQdk/w-d-xo.html

  • @bhaiyandcompany
    @bhaiyandcompany 4 ปีที่แล้ว

    I am not getting that if we are not giving the length of the List so how it can be get filled??

  • @AshuSingh-zf4bw
    @AshuSingh-zf4bw 3 ปีที่แล้ว

    Wow. Just Amazing Content. Learning.so much through you 🙂

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

      Happy to hear that!

  • @simarpreetsingh6419
    @simarpreetsingh6419 3 ปีที่แล้ว

    @codebasics Sir The creation of class stack is not helping in VScode please help
    Input:
    from collections import deque
    class Stack:
    def __init__(self):
    self.container = deque()
    def push(self, val):
    self.container.append(val)
    def pop(self):
    return self.container.pop()
    def peek(self):
    return self.container[-1]
    def is_empty(self):
    return len(self.container) == 0
    def size(self):
    return len(self.container)
    s = Stack()
    s.push("45")
    s.push("34")
    s.peek()
    s.size()
    s.pop()
    s.peek()
    Output:
    No output is coming its empty
    Please Help anyone

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

      u've to print the operations like follows:
      print(s.peek()) and so on !

    • @simarpreetsingh6419
      @simarpreetsingh6419 3 ปีที่แล้ว

      @@tejassarnaik3108 shit that's some serious stupidity on my part... Thanks sir

  • @awesomeGuss
    @awesomeGuss 2 ปีที่แล้ว

    ayooo
    the repercussions for clicking the solution without doing the exercises has me weak🤣🤣🤣
    he litterally said your laptop's going to get corona virus🤣🤣 if you don't do the work first😂

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

    Create a video on how to crack the coding interview

  • @bigbang3211
    @bigbang3211 3 ปีที่แล้ว

    Instructions weren't clear, now i'm in quarantine

  • @sumitdhiman5381
    @sumitdhiman5381 4 ปีที่แล้ว

    can we do 2nd ques with the help of regular expressions? if yes then please tell me

  • @ujeshnada7281
    @ujeshnada7281 4 ปีที่แล้ว

    example of website is very useful

  • @AutusDeletus98
    @AutusDeletus98 3 ปีที่แล้ว

    i tried the exercise and run your solution.
    On the last example if I run this print(is_balanced("[a+b]*(x+2y)*{gg+kk}"))
    the answer is true.
    But on the debug mode the answer is false.
    not sure why though.

  • @Khanarmaanrokz
    @Khanarmaanrokz 4 ปีที่แล้ว

    Here is a different solution for second exercise
    from collections import deque
    def parenthesis_matching(equation):
    stack=deque()
    arr=deque()
    for ch in equation:
    stack.append(ch)
    for ch in stack:
    if ch=="(":
    arr.append("(")
    elif ch=="[":
    arr.append("[")
    elif ch=="{":
    arr.append("{")
    elif ch==")":
    try:
    arr.remove("(")
    except:
    return False
    elif ch=="]":
    try:
    arr.remove("[")
    except:
    return False
    elif ch=="}":
    try:
    arr.remove("{")
    except:
    return False
    if len(arr)==0:
    return True
    else:
    return False
    if __name__=="__main__":
    s=input("Enter the equation")
    print(parenthesis_matching(s))

    • @Khanarmaanrokz
      @Khanarmaanrokz 4 ปีที่แล้ว

      Put continue at the end of every condition too.

  • @zhengxijiang4087
    @zhengxijiang4087 3 ปีที่แล้ว

    why you use self.container? I am learning, I will think just self is enough, I don't know the reason self.container, thanks for help!

  • @mdnafis-dg4dn
    @mdnafis-dg4dn 4 ปีที่แล้ว

    sir please create a playlist about python algorithm

  • @xXmayank.kumarXx
    @xXmayank.kumarXx 3 ปีที่แล้ว

    12:10
    didn't know about the digital variant of this virus

    • @codebasics
      @codebasics  3 ปีที่แล้ว

      ha ha.. yes it exist :)

  • @vikashparmar841
    @vikashparmar841 4 ปีที่แล้ว

    Hey great content. Very very helpful.♥️

  • @nourm3385
    @nourm3385 4 ปีที่แล้ว

    Thanks for this Video it's awesome!
    Please can you tell me how to puch another value for every node in stack without to adjust the Class Node..?

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

    Pandemic is over. So is it ok to click the solution link before I solve? hahahah Thanks for these videos!!

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

      Pandemic is over but COVID infections are still going on 😧 So be careful when click on the solution link 😆🤣

  • @muzammilomarzoy6616
    @muzammilomarzoy6616 10 หลายเดือนก่อน

    Day 2 : 5:06

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

    Hey man my laptop got virus I think this happend due to checking the solution before doing it 😂😂😜. Anyway Thankyou buddy.

  • @DiaaHaresYusf
    @DiaaHaresYusf 2 ปีที่แล้ว

    I think its better my friend if you make the container self._container instead of self.container , private property

  • @ramyavidiyala1293
    @ramyavidiyala1293 4 ปีที่แล้ว

    Why is implementing Stack using a deque a better option than implementing stack using a linked list?

    • @sayantanisaha
      @sayantanisaha 3 ปีที่แล้ว

      Its that we don't have to copy the already present elements in order to insert a new element....since linked list dynamic

  • @memestok893
    @memestok893 2 ปีที่แล้ว

    from collections import deque
    s=deque()
    a='We will conquere COVID-19'
    for i in a:
    s.append(i)
    m=' '
    for i in range (len(s)):
    rs=s.pop()
    m+=rs
    print(m)

  • @sukurcf
    @sukurcf 4 ปีที่แล้ว

    How would you manage this history in terms of data structure if you are browser developer?
    Not stack but Doubly Linked List. :-P. JFF. I would try stack too.

  • @LtMewS
    @LtMewS 4 ปีที่แล้ว

    Man I have been scratching my heads how to do the second Excersise for 1 day then I had finally to open solution 2 and now m like wait I could have done that.... But seriously damn nice way of implementing hash table to stack earlier I was first trying to see if I can do this with list and ord (of those brackets) to compare them and came up with complicated program but at the end it doesn't work on all test cases I found this to be much better but the last part of the code is really difficult to understand

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

    ThankYou

  • @meralmaradia4774
    @meralmaradia4774 2 ปีที่แล้ว

    But how we can overcome the challenge of memory using deque rather than list ?

  • @33v4.
    @33v4. 3 ปีที่แล้ว

    I'm watching on my phone and now I'll have to wait till tomorrow to click that link when I'm get my PC 😅 you never know right

  • @vishnupandey3390
    @vishnupandey3390 2 ปีที่แล้ว

    thanks for the support you are adding to the community 🙏

  • @ashwinvarma9349
    @ashwinvarma9349 4 ปีที่แล้ว

    what is the difference between append and push?

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

      They are the same thing ashwin . In arrays or linked list when we add element we are appending elements while in stack we say we are pushing elements .

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

      append, push, put are all the same..just based on different data structures.

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

    i implemented same concept in leetcode problem. it's working but it failed for 9 testcases like '((' , '(['. then i modified it.
    In Exercise problem:
    class Solution:
    def mapper(self, c1, c2):
    operation = {
    '}': '{',
    ')': '(',
    ']': '['
    }
    return operation[c1] == c2
    def isValid(self, s: str) -> bool:
    stack = Stack()
    if len(s) == 1:
    return False
    for char in s:
    if char == '(' or char == '{' or char == '[':
    stack.push(char)
    if char == ')' or char == '}' or char == ']':
    if stack.is_empty():
    return False
    if not self.mapper(char, stack.pop()):
    return False
    if stack.size() != 0:
    return False
    return True

  • @jaheerkalanthar816
    @jaheerkalanthar816 4 ปีที่แล้ว

    sir please give some easy exercise,the second exercise kills my whole day but i can't find the answer,so i open the sollution,after the open solution i can't understand,most of the comment below in this tutorial is they cant do second exercise sir

    • @codebasics
      @codebasics  4 ปีที่แล้ว

      Sure. To be honest the exercise is not that hard. But sure I will look into it in future and also add more comments to solution so that you understand

    • @jaheerkalanthar816
      @jaheerkalanthar816 4 ปีที่แล้ว

      @@codebasics after open sollution then only realize the problem is not hard,then only realize I have to change the way of thinking ,thank you sir for your reply, I'm big fan of you sir,you r a best teacher ,take care of ur health sir

  • @KANISHKSAHUSIME
    @KANISHKSAHUSIME 3 ปีที่แล้ว

    Someone said when you were making this video you are the person who was closest to god

  • @SLSRPPRO
    @SLSRPPRO 2 ปีที่แล้ว

    best

  • @binnygupta1483
    @binnygupta1483 3 ปีที่แล้ว

    I did code in a different way. please anyone review my code
    def reverse_string(self,string):
    for i in range(len(string)):
    self.push(string[i])
    rev_string = ''
    for i in range(len(string)):
    rev_string += self.pop()
    return rev_string

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

    It really download COVID 19... All of the sudden, I'm sick, and so is my computer

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

    Dont try clicking on the solution without trying to solve it first my computer is broken because it installes the COVI-19 virus!