I have a two dimensional array and also have the start and end point. The array is initialized to zero and i have to update from the start to end position with one. What is the best algorithm to do it ?
For example if start and end position are (2,2) and (4,2) i need to start updating the values from 2,2 and end at 4,2. Rest of the array should be zero.
Just loop over the array from start index to end index.
it’s going to take
O(n^2)time but I think that’s the best you can do.