dp to space o(1)