IBM interview question

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