I said it was rhetorical
I also knew that wouldn't stop you. :-)
Personally, I look for diversity of experience - more languages/environments is better.
"Depends on how fast it *needs* to be"
Here everything is optimized for speed. RAM is cheap. Volumes are really high though. This is the first place I've ever worked where maximum performance software was really important.
"Or if you just want a solution and RAM is not a problem, read the whole thing into a HashSet and get O(1) lookups straight from the string you read in. "
Around here *money* is not a problem for hardware as long as you're buying off the rack (no exotics). With that answer I'd ask for a quick estimate of RAM required in the worst case of all SSN's being populated. What is the overhead of a HashSet (I have no idea without doing research)?
"Actually, the best way might be: allocate 125M of RAM, and on startup flip the corresponding bit to 1 for each SSN you read in. When you get a request, convert the SSN to long or whatever, divide by 8, look up the byte, and bitmask off the remainder to see if the SSN is valid. That way you don't have to keep any of the actual SSNs in memory at all, and your question is more or less moot. ;-)"
Yep, bit vector is the best answer (smallest and fastest).
"I've personally never been in a situation like that with SSNs, though. :-)"
That's a real program at a real company where I once interviewed in San Diego. The question generally produces the nice thought process you wrote down. It lets me see the thinking pattern.
Most frequent answer from soon to be rejected candidates is to suggest a binary tree, then fail to be able to calculate the memory requirements of the fully populated structure. They get tangled up in trying to figure out memory partitioning algos to swap to disk too.
The CD sounds intriguing but I don't know how applicable it is. We use very little Java and the stuff I need coded isn't even a web app.
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." --Albert Einstein
"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses." --George W. Bush
I said it was rhetorical
I also knew that wouldn't stop you. :-)
Personally, I look for diversity of experience - more languages/environments is better.
"Depends on how fast it *needs* to be"
Here everything is optimized for speed. RAM is cheap. Volumes are really high though. This is the first place I've ever worked where maximum performance software was really important.
"Or if you just want a solution and RAM is not a problem, read the whole thing into a HashSet and get O(1) lookups straight from the string you read in. "
Around here *money* is not a problem for hardware as long as you're buying off the rack (no exotics). With that answer I'd ask for a quick estimate of RAM required in the worst case of all SSN's being populated. What is the overhead of a HashSet (I have no idea without doing research)?
"Actually, the best way might be: allocate 125M of RAM, and on startup flip the corresponding bit to 1 for each SSN you read in. When you get a request, convert the SSN to long or whatever, divide by 8, look up the byte, and bitmask off the remainder to see if the SSN is valid. That way you don't have to keep any of the actual SSNs in memory at all, and your question is more or less moot. ;-)"
Yep, bit vector is the best answer (smallest and fastest).
"I've personally never been in a situation like that with SSNs, though. :-)"
That's a real program at a real company where I once interviewed in San Diego. The question generally produces the nice thought process you wrote down. It lets me see the thinking pattern.
Most frequent answer from soon to be rejected candidates is to suggest a binary tree, then fail to be able to calculate the memory requirements of the fully populated structure. They get tangled up in trying to figure out memory partitioning algos to swap to disk too.
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." --Albert Einstein
"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses." --George W. Bush