Pergunta de entrevista da empresa Airbnb

Given a 2-D int array, write an iterator that traverses it from left to right and top to bottom. The iterator has 2 methods - boolean hasNext() and int next(). The array can have rows of different sizes, so for e.g. 1, 2, 4, 5 5, 6 <null/empty>, 10, 40, 50 The 2D int array was represented as ArrayList<ArrayList<Integer>>().

Resposta da entrevista

Sigiloso

18 de nov. de 2015

I took the complicated route of having class variables to keep track of positions rather than just pre-processing the 2-D array into a flat queue and then polling the queue. The simple solution struck me like 10 mins after the interview got over. But, because there was absolutely no feedback or dialog, I just kept banging my head on the solution (which worked fine btw) that I had written initially. Also, I was stressed out and nervous for this interview which didn't help.