Hi,
Why does the solution use last_reach? It doesn’t seem to be very useful. Can we just do -
bool can_reach(const vector& A) {
int farthest_reach = 0;
for (int i = 0; i < A.size(); ++i) {
if (i > farthest_reach) {
return false;
}
farthest_reach = max(farthest_reach, i + A[i]);
}
return true;
}
We just need to update farthest_reach and check whether i goes beyond it, right?
edit: sorry abt the format, it seems to ignore the leading white spaces when display the post.