added a logn solution