The UK economy unexpectedly contracted in October, marking two months in a row of negative growth for the first time since the pandemic, new figures show.