Skip to content

Instantly share code, notes, and snippets.

@tiagopereira17
Created June 25, 2016 17:00
Show Gist options
  • Save tiagopereira17/0b2c1c1d5c1a9a75507becee763e9bfc to your computer and use it in GitHub Desktop.
Save tiagopereira17/0b2c1c1d5c1a9a75507becee763e9bfc to your computer and use it in GitHub Desktop.
Find the earliest time when a frog can jump to the other side of a river.
public class FrogRiverOne {
public int solution(int X, int[] A) {
if(A == null || A.length == 0) {
return -1;
}
int[] passed = new int[X];
for(int i = 1; i <= passed.length; i++) {
passed[i-1] = -1;
}
int missing = X;
for(int i = 0; i < A.length; i++) {
if(passed[A[i] -1] != -1) {
continue;
} else {
passed[A[i] -1] = i;
missing -= 1;
if(missing == 0) {
return i;
}
}
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment