update unique paths, using O(n) memory