Medium level code challenge solution