LC: Flatten 2D Vector - spiralgo/algorithms GitHub Wiki
The Essence:
For this problem, using two pointers to index the row and column of the vector is sufficient. Since there are empty 1D vectors, the row index needs to be implemented in accordance with this. When the current row does not have as many elements as the column index points, then the row should simply be moved to valid position.
Details:
It's useful to call the hasNext() method within next(). This would put the responsibility of finding the next valid index on to a single method.
The code implementation can be found here: https://github.com/spiralgo/algorithms/blob/master/src/main/java/algorithms/curated170/medium/Flatten2DVector.java