Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
How many variables do you need to keep track?
Two variables is all you need. Try with <code>x</code> and <code>y</code>.
Beware of empty rows. It could be the first few rows.
To write correct code, think about the <a href="https://en.wikipedia.org/wiki/Invariant_(computer_science)" target="_blank">invariant</a> to maintain. What is it?
The invariant is <code>x</code> and <code>y</code> must always point to a valid point in the 2d vector. Should you maintain your invariant <i>ahead of time</i> or <i>right when you need it</i>?
Not sure? Think about how you would implement <code>hasNext()</code>. Which is more complex?
Common logic in two different places should be refactored into a common method.