13.1. Draw It First

The importance of drawing diagrams cannot be overstated. Consider that while humans have only been using written language and mathematics for a few thousand years, we've been evolving to analyze visual problems (for example, can that rhinoceros catch me before I get to that tree?) for millions of years. We are generally much better suited to solving problems presented in pictures than those presented in text or numbers.

Whenever possible, draw a picture.

In some cases, the actors in these brainteasers are static, but more often they are changing or in motion. When this is the case, don't draw just one picture, draw many. Make a diagram for each moment in time for which you have information. You can often gain insight by observing how the situation changes between each of your diagrams.

If the problem involves motion or change, draw multiple pictures of different points in time.

Most problems are two-dimensional. Even when a problem involves three-dimensional objects, the objects are often constrained to the same plane, allowing you to simplify the problem to two dimensions. It's much easier to diagram two dimensions than three, so don't work in three dimensions unless you have to.

If the problem is fundamentally a three-dimensional problem, you should assess your relative abilities with drawing and visualization before proceeding. If you're not very good at drawing, your diagram of a three-dimensional problem may do more to confuse than elucidate. On the other ...

Get Programming Interviews Exposed: Secrets to Landing Your Next Job, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.