solve previus logic