http://www.dev102.com/2008/07/21/a-programming-job-interview-challenge-13-brackets
Basically the question this is looking to solve is handling proper expression syntax/precedence similar to the standard calculator problem of solving 5+5/5=6 as opposed to solving it as 2.
Example of a legal expression: “([](<{}>))”.
Example of an illegal expression: “({<)>}”.
Which involes a much simpler version of Prefix or PostFix/Reverse Polish Notation (
http://en.wikipedia.org/wiki/Postfix_notation
) than the math expression since there are only pairs of operations. A rather basic psuedo code implementation of this could be done as follows
HashTable Close [ ")" -> "(", "}" -> "{", ">" -> "<", "]” -> “[" ]; Stack holder;
Read expression
do while not end of expression {
if(close.ContainsKey(expression[i])) –Check to see if letter is a closing operand
{ –Reached closing operand, top of stack should be matching opening operand
if(close[expression[i] != stack.PopTop()) throw InvalidExpressionException
}
Push (expr[i])
} –Do looping to end of expression
BloggingContext.ApplicationInstance.CompleteRequest();
[...] http://dotnetchris.wordpress.com/2008/07/30/a-programming-job-interview-challenge-13/ by Chris Marisic. [...]
Pingback by A PROGRAMMING JOB INTERVIEW CHALLENGE #14 - 2D GEOMETRY | Dev102.com — August 5, 2008 @ 5:10 am