My Current Favorite Interview Problem Memoize

Just added memoize to my growing catalog of interview questions.

Summary of the Challenge

Part 1 is a discussion. Part 2 gets to the code. You can skip straight to 2 when time is short. This problem is particularly useful for gauging JavaScript familiarity since it takes advantage of functions as objects and closures.

There’s a lot of jargon in the question, but that’s not the point of this challenge. Make sure they understand the question. You might gauge how willing they are to ask questions, but only gently. Don’t put them on the defensive just by the wording of the question.

Part 1: You have a number of expensive pure functions. During the course of any given hour these functions are each called with a small number of inputs. Hour over hour the inputs vary dramatically. Describe how you could improve the performance of the system.

Candidate behaviors to look for: Caches the results and bypasses the expensive function calls when the answer is cached. Memoization. (See formal write up for details.)

Part 2: Write a higher order function (a function that takes a function and returns a function) that accepts a function of arity 1 and returns an identical, memoized function. (See formal write up for candidate template and example solution.)

Good At Differentiating Candidates

You will find that some candidates will solve the problem handily, refactor, then easily run through the examples. Other candidates might have to be coached more through the implementation, but should at least be able to step through the execution of the examples.

Whole Root Challenge

Interviewed another candidate today.  A colleague used a challenge based on computing square roots.  It’s a very simple problem and still gives a quick feel for a candidate’s comfort with JavaScript and solving problems with code.

I’ve added it to the (tiny) suite of interview code challenges. See github.com/ManagerJS paper-code/whole-root. I hope you find this useful conducting interviews and preparing for interviews.

Here’s a copy of the challenge for your convenience: