2
public boolean canReach(String s, int minJump, int maxJump) {3
if (s.charAt(s.length() - 1) != '0') return false;5
Queue<Integer> queue = new LinkedList<>();8
// This variable tells us till which index we have processed11
while (!queue.isEmpty()) {12
int idx = queue.remove();13
// If we reached the last index14
if (idx == s.length() - 1) return true;16
// start the loop from max of [current maximum (idx + minJump), maximum processed index18
for (int j = Math.max(idx + minJump, maxReach);19
j <= Math.min(idx + maxJump, s.length() - 1);21
if (s.charAt(j) == '0') queue.add(j);24
// since we have processed till idx + maxJump so update maxReach to next index25
maxReach = Math.min(idx + maxJump + 1, s.length() - 1);