start
index to it.true
.
c. If the value at this index is already visited (marked as -1), continue to the next iteration.
d. Mark the current index as visited by setting its value to -1.
e. Add the indices i + arr[i]
and i - arr[i]
to the queue if they are within the array bounds and not yet visited.false
.