3 ms·
>>"Back when I was at Google, I was mostly interviewing people for “Developer Advocate” positions, and a lot of people somehow got into the process
by throwaway_374 10y ago
>>"Back when I was at Google, I was mostly interviewing people for “Developer Advocate” positions, and a lot of people somehow got into the process without being able to code at all. So, early on, I’d ask. “You’ve got a list of objects, write some code to select one of them at random. Any language, don’t worry about syntax, assume the built-in random function is good enough.”
That was actually a nice question: If you wanted to dive a little deeper, you could ask the candidate to sketch in unit tests. And if you’re talking to somebody super-technical, ask “Your code is in production and sometimes it’s throwing illegal-index exceptions under heavy load. What’s going on and how do you fix it?” Just because that’s a cool problem, very real-life, and most people smile when they get it."
Genuinely curious as to what the reasons for illegal-index exceptions under heavy load would be? I genuinely can't think of any reason. Perhaps the problem is under specified. Unit-testing would need to be seeded to be reproducible.
- fnbr 10y agoI could see it being some sort of shared memory problem, where the system is misallocating memory because it's running out of free space.
- joshuamorton 10y agoOr similarly, the application is multithreaded and the list length at `idx = randint(list.length)` time is greater than the next line `obj = list[idx]`, when you pick one of the last few indices and objects are removed.
- jsnell 10y agoI think the implication is that another thread is modifying the list at the same time, and there's inadequate locking.
- joshvm 10y agoI think you need more information about the code and what situation it's in. Illegal index presumably means trying to access part of the list that's no longer there. If it's a shared data structure, perhaps something is popping the list while another is trying to access the last element. But without anything else to go on, who knows, maybe you accidentally stored the length of the list in a data type that could overflow? Though in the first part of the question (ignoring the next bit), is the answer anything more complex than import random; random.choice(my_list)?