TECHHARPER'S HUB
Create Your First Project
Start adding your projects to your portfolio. Click on "Manage Projects" to get started
Daily Coding Problem 0: 2D Iterator Class
Project type
Coding Problem
Date
22 December 2023
Location
Saskatoon
Good morning! Here's your coding interview problem for today.
This problem was asked by Uber.
Implement a 2D iterator class. It will be initialized with an array of arrays, and should implement the following methods:
next(): returns the next element in the array of arrays. If there are no more elements, raise an exception.
has_next(): returns whether or not the iterator still has elements left.
For example, given the input [[1, 2], [3], [], [4, 5, 6]], calling next() repeatedly should output 1, 2, 3, 4, 5, 6.
Do not use flatten or otherwise clone the arrays. Some of the arrays can be empty.
The code is available on GitHub: https://github.com/Harpreet1716/2D-Iterator-Class/tree/main