Stepping back

One of my common interview question is writing a function which takes a string like “2+2” and returns an integer result.

I asked to do that for quite big set of rules initially (support several operators, multiple digit numbers etc.). However, it was overwhelming for candidates. As result I scaled it down to several simplistic cases.

I ask to write a method which can calculate “2+2”. And it takes them 30 seconds to do that.  I ask them to change a solution to handle “2+2+2”. It takes them 3-4 minutes and next thing I ask to do “12+2+2” (support of multiple digit numbers) or “2+2-2” (support of operator minus). And boom… It takes them 30 minutes to do this.

The question is “Why?”

People are wired to always push forward. As result, they take their previous solution and try to hack it into a new one which will support this new requirement. As result, the solution become so messy and complicated by second or third time around that it’s impossible to update it.

However, all they need to do is to step back for one second and think about new problem and new solution (vs trying to hack the old solution).

 

Comments are closed.