by ralfd · 9y ago · 0 comments
Ahm ... I would probably just naively brute force loop over the sets, because modern CPUs are insanely fast and I am filthy lazy. And if there is a performance problem I super lazily look up the filtering methods of the language-library.
What would the correct answer here be? Make a hash or something for constant lookup cost?
With Python(my bread and butter), I would simply use the built in intersection set class method: https://docs.python.org/3/library/stdtypes.html?highlight=se...
If space complexity is not a requirement, wouldn't it be better to iterate over each list and keep track of the occurrences of a digit in a dictionary (whichever keys have 3 occurrences are thus shared)?
That way you could get the value in O(n) time. Or is there something I'm missing?
"How many times is this going to run? Is it going to be cheaper to do any naive thing and move on to the next ticket, or should I take the time to actually optimize this?"
That's usually the correct answer, and one I never see in interviews (either asked or offered).