PIXELBANKv9.1.0
Menu

Implement an iterator to flatten a 2D vector. Support next() and has_next() operations.

Input: 2D vector as JSON, then operations separated by semicolons. Output results of next() calls.

Example:

Input:
[[1,2],[3],[4]]
next;next;next;has_next;next;has_next
Output:
1
2
3
True
4
False
Reasoning:
  • The input 2D vector [[1,2],[3],[4]] is initialized for iteration.
  • The next() operation is called three times, yielding the values 1, 2, and 3, which are the first elements of each of the first three sub-vectors.
  • The has_next() operation checks if there are more elements and returns True because there is still an element 4 left in the vector.
  • The next() operation is called again, yielding the value 4, which is the last element in the vector.
  • The final has_next() operation returns False because there are no more elements left to iterate over in the vector.

Constraints:

  • 0 <= rows <= 100
  • 0 <= cols <= 100
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Flatten 2D Vector - Easy | PixelBank