I had an interviewer ask me to do a string comparison in C++ without using any libraries. I was probably already out when I asked whether String was a library....
You should mention that a proper normalizing comparison requires the full ICU library, loading many Unicode data point files, and several conversion functions. You could write it, with access to the standard, but it'd take you a few years -- assuming you'd also need to write the loading functions without any libraries. :D
Just out of curiosity, if the goal is simply to compare two strings, would this still be necessary? I assume that it must be possible to represent any string, regardless of encoding, in some lower-level way. All we'd want to do is to make sure that the two strings are the same when compared in this way, like a list of "characters" or even just an array of arbitrary values...
Yes. Presumably you want to do a real-world comparison, not a byte-for-byte comparison. There are numerous rules in Unicode on how that should be done. Thanks to combining characters, precomposed characters, ligatures, and some other features, there are numerous ways two equal strings can be encoded.
But string comparison is one for-loop, no? Sure, in production you'd use String, but what's so weird in that question? A person who cannot compare two arrays might not be good fit for every job.
I don't recall whether it was one or two, but I did end up simply working through using char values. I was able to solve the problem as well as one can on a whiteboard, but I think it took me longer than they wanted (and I likely shot myself in the foot asking whether it was a library)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I had an interviewer ask me to do a string comparison in C++ without using any libraries. I was probably already out when I asked whether String was a library....
You should mention that a proper normalizing comparison requires the full ICU library, loading many Unicode data point files, and several conversion functions. You could write it, with access to the standard, but it'd take you a few years -- assuming you'd also need to write the loading functions without any libraries. :D
Just out of curiosity, if the goal is simply to compare two strings, would this still be necessary? I assume that it must be possible to represent any string, regardless of encoding, in some lower-level way. All we'd want to do is to make sure that the two strings are the same when compared in this way, like a list of "characters" or even just an array of arbitrary values...
Yes. Presumably you want to do a real-world comparison, not a byte-for-byte comparison. There are numerous rules in Unicode on how that should be done. Thanks to combining characters, precomposed characters, ligatures, and some other features, there are numerous ways two equal strings can be encoded.
Interesting and a bit scary! I’d have thought it should be possible to force some kind of ordering to prevent that...
But string comparison is one for-loop, no? Sure, in production you'd use
String
, but what's so weird in that question? A person who cannot compare two arrays might not be good fit for every job.I don't recall whether it was one or two, but I did end up simply working through using char values. I was able to solve the problem as well as one can on a whiteboard, but I think it took me longer than they wanted (and I likely shot myself in the foot asking whether it was a library)