Okay, I've been on some hard interviews, but this was ridiculous. I was asked one question, given a pen, paper, calculator, definition of "URL-safe" characters, and 20 minutes to complete the question. The question was (as best I can remember):
Write a function to generate a unique URL-safe string that represents a given point in time for a file modification on an IIS web server that we're deploying tomorrow. The resolution of a "point in time" is one second.
.NET RegEx pattern for "URL-safe" characters =
[0-9a-zA-Z\$\-\_\.\+\!\*\'\(\)]
I panicked and just wrote out my thinking instead of writing actual code. They dismissed me after viewing my "answer" because I didn't actually write any code. :(
What I wrote was something like:
- 365 days in a year so "day of year" can be represented in 2 bytes - 4 digits in year (0 - 9999) so year can be represented in 3 bytes - 2 digits in hour (0 - 23) so year can be represented in 1 byte - 2 digits in minutes (0 - 59) so minutes can be represented in 1 byte - 2 digits in seconds (0 - 50) so seconds can be represented in 1 byte TOTAL: 2+3+1+1+1 = 8 bytes total that use 0 - 255 - URL-safe range == 10 + 24 + 24 + 10 == 0-9 + a-z + A-Z + special chars == 68 - 4 bits required to represent URL safe char ANSWER: - A byte is 8 bits - Only 4 bits per byte needed to represented the 8 bytes in a date - 8 / 2 = 4 FINAL ANSWER: - Only 4 actual bytes needed to represent hash
In other words, the timestamp hash could reasonably be represented in 4 URL-safe characters at most.
How would you have answered this?! I feel like I'm a pretty good developer but it's been many years since I've had to worry about calculating powers of two!
This seems almost like a FizzBuzz problem... based on requirements
DateTime.UtcNow.ToString("yyyyMMddhhmmss");
or something very similar to it is a good answer and as an interviewer I would be highly skeptical of anyone who didn't write any code because they chose to make the problem needlessly complicated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With