stacks and queues

A collection of 4 post

Stone Wall

Problem You are going to build a stone wall. The wall should be straight and N meters long, and its thickness should be constant; however, it should have different heights in different places. The height of the wall is specified by an array H of N positive integers. HI is the height of the wall from…

Nesting

Problem A string S consisting of N characters is called properly nested if: S is empty; S has the form “(U)” where U is a properly nested string; S has the form “VW” where V and W are properly nested strings. For example, string ”(()(())())” is properly nested but string ”())” isn’t. Write a…

Fish

Problem You are given two non-empty arrays A and B consisting of N integers. Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river. The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish P is initially upstream of fish Q…

Brackets

Problem A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: S is empty; S has the form “(U)” or ”U” or “{U}” where U is a properly nested string; S has the form “VW” where V and W are properly nested strings. For example, the string…