Snapshot set iterator — the problem said the return order didn't matter.
After I said I needed two data structures — a list of logs and a dict — and laid out my rough approach, the interviewer asked if I had another way to do it. Then he suggested that instead of one shared logs list for all keys, it could just be a dict where each key has its own logs, rather than all keys sharing one list of logs. I thought, well, since you already said it, I'll just write it your way. But as I was writing it, I realized his approach had no advantage over mine in either time or space, so I pushed back on it. He thought about it for a second and admitted, yeah, both work, just pick one and write it.
I was a bit nervous during the interview and wrote a bunch of dumb little bugs. By the time I'd mostly debugged it, the printed output still wasn't right, even though printing out the logs themselves was fine. Looking back, I realized I just hadn't written the most important part of the iterator — the iter function. That's what was causing the weird print output at the time. The interviewer suggested I write a print statement to debug it — when actually writing iter return self right then would have wrapped everything up perfectly. Honestly, the interviewer's presence the whole time only made things worse. He didn't give any useful hints either — at one point I'd even forgotten to delete the key in remove, and when I caught it during debugging and went to add it back in, he questioned whether I should even add it. Like, fine, don't give me hints, but can you please stop getting in my way.
Discussion
Loading comments…