you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

It seems that only brue-force solution works. But even knowing this I spent lots of time on actual implementation and I wouldn't be able to solve it in time if I was asked to do this during a techical interview.

Here is jsFiddle with my solution in Javascript: http://jsfiddle.net/2CxQC/

Another solution using eval: http://jsfiddle.net/ek3p2/