Avatar


Python

Balanced brackets in Python

Apr 10, 2020


You can find the problem here and try to solve it by yourself. Follows my solution and then a concise explanation. def isBalanced(s): """ Checks if s contains balanced brackets. :returns: 'Yes' if s is balanced otherwise 'NO' :rtype: str """ parentheses = { '{': 1, '[': 2, '(': 3, '}': -1, ']': -2, ')': -3 } stack = [] for elem in s: elem = parentheses[elem] if elem 0: stack. Read More…

RPN calculator in Python

Dec 17, 2019


A week ago, I did an interview for an R&D position in a company. Apart from some other technical and logical tasks, I was asked to implement a simple rpn calculator, with the basic operators: sum, subtraction, product, division and square root. For those who don’t know what an rpn is follows a brief description from the beginning. Infix notation Infix notation is the notation commonly used in arithmetical and logical formulae and statements. Read More…