Rafael interview question

To explain my solution briefly, design and implementation.