Skip to main content

Posts

Showing posts from September, 2024

Simple arithmetic expression evaluator in Python

Taking user input for two variables, an arithmetic operator and computing the results is very basic. This article projects a fresh look at extending the simple calculator by evaluating complex arithmetic expressions input by the user while also providing a mechanism to include the last computed value in a follow-up expression. All of these in only a few lines of code, by exploiting the Python's eval function.

Implementing Monotonic Stack in Python

A monotonic stack is an extension of the Stack data structure in which the elements of the stack are in either increasing or decreasing order. The stack in which the items are in increasing order is called the monotonically increasing stack, the top element of such a stack will be the largest of all the elements below. On the other hand, if the items are arranged in a decreasing order then the stack is called a monotonically decreasing stack, on which the top element will be the smallest of all the elements below. Monotonic stacks are very popular in competitive programming.