# STACK

## Next greater element in an array

Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element x is the first greater element on the right side of x in array. Elements for which no greater element exist, consider next greater element as -1. Examples: a) For any [...]

2017-07-15T14:01:29+05:30Categories: Data Structure|Tags: |

## Largest rectangle in a histogram

Problem: Given an array of bar-heights in a histogram, find the rectangle with largest area. Solution: Assuming, all elements in the array are positive non-zero elements, a quick solution is to look for the minimum element hmin in the array. Then numElements * hmin can be one of the possible [...]

2017-03-01T11:54:22+05:30Categories: Data Structure|Tags: |

## Stock span problem

We are given a list of prices of a stock for N number of days. We need to find stock span for each day. Span is defined as number of consecutive days before the given day where the price of stock was less than or equal to price at given day. For [...]

2018-09-28T11:57:54+05:30Categories: Data Structure|Tags: |

## Expression (Postfix, Prefix, Infix) conversion

Arithmetic expression evaluation In expression (A + B) * C, the addition of A and B to be done first before the multiplication. Infix requires the parentheses to force the performance of the addition before the multiplication. However, when A + B was written in prefix, the addition operator was [...]

2019-04-13T19:42:32+05:30Categories: Data Structure|Tags: |
Go to Top