Pergunta de entrevista da empresa Quantcast

Given alphanumeric zip codes, and a (start, end) zip codes - list out all the zip codes that fall in the range (start, end). Assume zip codes are of fixed length. Ex: AB123Z,... start = AB123C, end = AC999B

Resposta da entrevista

Sigiloso

24 de mar. de 2017

Confirmed, start and end exist in the given set of codes. Suggested sorting the zip codes and going with binary search on the start. After finding the start, list out codes until the end is found. The interviewer then said, the zip codes data is not clean. He said it might contain lower case letters. Then I suggested a one time pre-processing or case insensitive comparison. Then he said, we want to optimize storage space, and gave examples of zip codes that have common prefix. I suggested a trie structure, but didn't explain well on how to do range search. He changed the problem to 3 letter zip codes, and I used a HashMap to simulate a tree structure. Wrote some code, and I know I lost it by then. :) Looks like a general tree with ordered nodes, and leaf nodes connected would help in this range query. B-tree, B+ tree or any other advanced structure? Wouldn't a complex data structure waste more space with pointers?

1