Block Interview Question

Regular CS and algorithm question. Nothing tricky.