5 ms·
I noticed one of the challenges is "reverse a string." Can I just rant a little about how much I hate that as an interview question? It's meaningless to revers
by akersten 5y ago
I noticed one of the challenges is "reverse a string." Can I just rant a little about how much I hate that as an interview question?
It's meaningless to reverse a string. Not just in the "there's no purpose to doing it" sense (very true) but genuinely in the "it literally isn't a defined operation" sense. If you've only lived in the nice insulated world of ASCII or a mostly-ASCII-like language, you might scratch your head - just put the letters in backwards order, right?
Well, what do you when you hit a Unicode joiner? Or a multi-byte emoji? Maybe your reversing scheme is clever and looks at "whole codepoints" or whatever. But then what happens when you normalize the "reversed" string? Or what about the modifier characters that affect the previous/next character - how to treat those? I've never been satisfied with anyone's answer to these questions, because the problem is invalid from the start. You can't "reverse" an arbitrary string, it's not a well-defined operation.
- julienreszka 5y agostr.split('').reverse().join('')
- Karawebnetwork 5y agoIn a tongue-in-cheek tone: Woah, so old school. We would never hire you! You have to show that you know ES6! [...str].reverse().join('')
- jandrese 5y agoWhich would fail. You got the directional formatting characters in the wrong order. It is 2022. If your code doesn't treat all strings as Unicode it is broken.
- yehoshuapw 5y agoThere is a (slight, but important) difference between the syntactic meaning, and the semantic meaning. you are correct that reversing a string gives back irrelevant things. (and you don't need to go that far: what does a reversed word mean?) however, in the sense of a list of characters, the content is irrelevant.
- MattGaiser 5y agoI have learned not to ask these sorts of questions outside hobby projects. It is rarely appreciated.
- charcircuit 5y agoI recommending googling "grapheme cluster"
- Eduard 5y ago> I noticed one of the challenges is "reverse a string." Can I just rant a little about how much I hate that as an interview question? I find "reverse a string" a good interview question then! If the applicant got lost in considering all possible interpretations instead of just solving it how 99% of humans/engineers would understand it, then they will likely be unfit for working in a team and/or have poor communication skills.
- alanbernstein 5y agoThat's harsh. Sounds like a thoughtful candidate who understands edge cases to me.
- paulluuk 5y agoBest: solve the problem, but also add the caveat that _technically_ there are edge-cases that wouldn't work. Worst: spend the entire interview explaining why you can't solve this problem.
- jandrese 5y agoYou are weeding out all candidates who understand Unicode. This is exactly the sort of problem that a good engineer would keep an eye out for because it's almost certainly going to explode with edge conditions if you try to do it the "obvious" way. Unless you're giving that problem and then hitting the input with a string that includes directional formatting characters. Because that's exactly what is going to happen in real life. The only good thing about that question is at least you didn't ask them to casefold the string.
- renewiltord 5y agoNo, not all, probably not even many. There are lots of candidates who know Unicode who would just say “I’ll assume that we have just ASCII characters unless you think I should consider Unicode” and if you say the latter, then they can say “Well, I could reverse it by just ensuring the text appears right to left, or perhaps by reordering each grapheme cluster to the end, or something like that. Let me know if you want one of those, otherwise I’ll just write it assuming you mean A”. The magic of engineering isn’t doing what you’re told. It’s understanding and solving a problem someone has told you about. My org doesn’t need the guys who need exhaustive instructions to take the next step. It needs those who can make good Bayesian inferences, reason inductively, and figure out problems. So yes, it does filter out people with lots of knowledge who nonetheless lack these skills.
- paulluuk 5y agoHa, I had the same challenge and was actually annoyed to find out that Javascript doesn't have a builtin function like str.reverse(). I totally see your point, though.
- htilford 5y agoThe fact that it most people think it's a well-defined operation is what makes it a useful question. A total newbie who doesn't know how to code will fumble. A junior engineer will get to the simple solution. A senior engineer will ask you to define it better. Etc... It's an effective tool for determining level because there isn't a limit on how much depth you can go into about it.
- technion 5y agoI'm jaded enough to imagine that if I ask someone to define it better and try to give a "senior" response that covered codepoints, an interviewer will write down "struggled with simple question". Edit: That seems consistent with a statement made in another response.
- Doxin 5y agoI feel like the best way to tackle questions like these is to first jot down a simple solution and then point out the various ways it doesn't work.