Clover interview question

General algorithm question with efficiency accounted for