v1 of sol
deal with edge case of empty list