log n solution