DEV Community

Discussion on: Day 1 - Balanced Brackets

Collapse
 
prathamesh404 profile image
Prathamesh

Disclaimer: If in case violates the requirements, please let me know

  • Was it a necessary constraint to create a stack from scratch? List in python have underlying capability that works like Stack having same time complexity of pop(), append() as O(1),
  • Also a HashMap or dictionary in python to map key: values as{open:close}. Which also has O(1) time complexity for accessing an element. e.g.
mapping = {
 '{':'}',
 '[':']',
 '(':')'
}
  • Code redundancy can be reduced, long conditional statements makes code less readable. e.g. if ((topmost_element == '[') and (x != ']')) or ((topmost_element == '(') and (x != ')')) or ((topmost_element == '{') and (x != '}')):

Thanks.