Clover Interview Question

General algorithm question with efficiency accounted for