3 ms·
Sure, there are always edge cases. There are cities with no street addresses (check out Carmel-by-the-sea for some craziness: http://en.wikipedia.org/wiki/Carme
by Jemaclus 13y ago
Sure, there are always edge cases. There are cities with no street addresses (check out Carmel-by-the-sea for some craziness: http://en.wikipedia.org/wiki/Carmel-by-the-sea http://en.wikipedia.org/wiki/Carmel-by-the-sea). How do you parse an address when the address is "10th and Lincoln"? Or when you wind up with something like in rural Wisconsin where the address is "N323 W77532 County Road 120, Wherever, WI"? Or when you wind up with two cities that are different but the USPS, the residents, and Google/Bing consider them the same place, like Rockville and Potomac, MD?
Don't even get me started on the Virgin Islands or Puerto Rico...
But for the purposes of the interview question, there are "perfectly valid" assumptions that you can make to solve the task before you. I'm not asking you to solve the entire scope of the problem -- I've been working on this for over a year with varying degrees of commitment, and I assure you I have not solved the entire scope of the problem. I don't expect you to figure it out in 15 minutes.
You can assume that there are 50 states (but that leaves out the Virgin Islands and Puerto Rico). You can assume that ZIP codes have 5 digits (but maybe someone provided all 9 digits, or maybe they left it off completely). You can assume that all streets end in a reasonable suffix (but that ignores post-directional suffixes or the examples you provided).
However, by making assumptions, you can more quickly solve the problem in an interview context. As long as I understand the assumptions you're making, I can judge the quality of your output. It won't solve everything, but maybe it's better to parse 99% of addresses using one simpler algorithm and then handle the edge cases using a second (or third, or fourth, or fifth) algorithm.