Bloomberg Interview Question

The question is quite easy. Check whether a given string has valid parentheses. For example, { needs to match }, ( matches ) and [ matches ]. And you have to check whether they are in the right order. The follow-up question is to check the valid string again but with given pairs. Say the pairs are "ab cd". That means 'a' needs to match 'b' and 'c' needs to match 'd'.

Interview Answer

Anonymous

Dec 7, 2015

Use hashmap to store pairs. Use stack to check the order.