I was going through a dp problem, there I have to initialize the matrix with default(-1) values for memoized solution. And felt the need.
We can initialize the 1D array in java like this => Arrays.fill(arr, -1)
what for 2D array…?
Otherwise I have to run a nested for loop to initialize the matrix with default values, that includes more lines of code, and doesn’t look appropriate when you are solving a dp problem.
Rushil Patel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.