3 ms·
As a full-stack developer, I really dislike these kinds of questions for the reasons outlined by others, just like I hate having to sort lists. In real-life, I
by Jemaclus 9y ago
As a full-stack developer, I really dislike these kinds of questions for the reasons outlined by others, just like I hate having to sort lists. In real-life, I do some version of sort(foo) or foo.sort() and call it a day. I don't need to know whether it's using Quicksort or Heapsort or whatever. The built-in sorting algorithm for our chosen language is generally not going to be the bottleneck of anything, and if it does wind up being a bottleneck, you look up alternatives and implement them. Same thing goes for binary trees or inverted indexes or graph searching or something. The real-world solution for those things in the real world is almost always going to be to use some out-of-the-box solution, like the built-in sort or Elasticsearch or Redis or something. Sometimes it's useful to see if they understand how the underlying thing works, but most of the time it doesn't.
I very much prefer application-level problems that have a hundred different possible solutions. For example, for a US developer, I might ask the following question: "Given the address 123 Main St, Boston, MA 00215, write an algorithm that will break it apart into its components of number, street, city, state, and ZIP." The reason I like this is that A) everyone who lives in the US can identify those parts on sight, requiring no special domain knowledge, and B) there are a hundred ways to do it.
I often get solutions like "I'll write a regex" (Okay, write one!) or "I'd use some sort of machine learning" (Okay, write something!). Most people will start off and say "Ok, I'll split on commas and wind up with [123, 'Main St', 'Boston', 'MA 00215'], and then..." and work there way from there.
So then I can throw in any number of wrinkles.
* What if there are no commas? (this breaks the regex solution)
* What if it's "San Francisco" instead of "Boston"? How might you decide you've gotten the whole city name and not just part of it? What about "Palm Beach" vs "West Palm Beach"?
* What if we have "123 St Francis Street"? Or "12A Main St"?
* What if it's "123 Main St West Palm Beach FL"? Is it "Main St West" or is it "West Palm Beach"? How might you tell?
And so on. The possible ways to write an address are endless, and there are no correct answers right out of the box to parse the address. This gives me a glimpse into the developer's mindset: how do they initially scope the problem? do they existing solutions or do they reinvent the wheel all the problem? Do they know how to write a regex? Are they bluster or not? Can they adapt when you throw curveballs at them? Do they start thinking ahead of you and say "ok, if Boston could be San Francisco, then this problem could also happen in the street name..."? And so on.
This becomes much more of a dialogue and a discussion of the problem and possible solutions than sitting there watching someone write code under pressure and tut-tutting when they do something wrong.
(This is an actual issue I ran into on the job, so it's not just a hypothetical one.)
My two cents. Good luck.