Airbnb phone screen, the 2D iterator with remove
Airbnb phone screen, the 2D iterator with remove
Had my Airbnb phone screen Tuesday. One question, 45 min, interviewer pasted the prompt and we started coding pretty much right away.
You get a list of lists of ints and build an iterator over it with hasNext, next and remove. remove deletes whatever the last next() returned, and it has to delete it from the actual underlying lists, not a copy. Some inner lists can be empty, sometimes a few in a row.
I kept two indices, row and col. hasNext skips past empty rows and has to be safe to call multiple times without moving anything, which I didn't think about until he called it like three times back to back in his test. remove is where most of my time went tbh. After you pop the element, the next value shifts into the slot you're pointing at, so if you already advanced col you skip it. I ended up tracking where the last returned element was separately and fixing col after the delete. Calling remove twice without a next in between should throw too.
Wrote my own tests at the end, he asked for complexity, finished with maybe 5 min left.
Recruiter emailed two days later, moving to onsite. Anyone know if the onsite still has the code review round?