4 ms·
And my favorite answer to questions like this is, "Can I just use grep (or shell commands in general)?" Grep, uniq, wc, and a few others can be treated as pipe
by michaelteter 3y ago
And my favorite answer to questions like this is, "Can I just use grep (or shell commands in general)?"
Grep, uniq, wc, and a few others can be treated as pipeline data transformers to answer questions like this interview question. As long as you make some smart decisions about the order of operations, you can usually get performance on par with what you might write custom code for.
- optymizer 3y agoBecause shell command injection and process spawning time are not always acceptable side-effects.
- michaelteter 3y agoAnd one of the appropriate questions would be, “Is this a one-off or rare request, or does this need to be productionized? And how sensitive is the response time? And if it must be fast and frequent, then why are we not using some form of indexed db”
- gpderetta 3y agoYou would definitely pass if I interviewed you, as long as your solution was reasonably efficient. I would love to interview a candidate that can show they can use command line tools effectively.
- kasdi 3y agoOut of curiosity, how would you solve this particular problem with shell commands?