IBM Interview Question

Using the code below add this functionality to it. Can it be optimized further?