My solution used inefficient list construction