5 ms·
I have written countless programs but would not be able to answer that without first turning to google. You might have screened out plenty of valid applicants w
by marliechiller 3y ago
I have written countless programs but would not be able to answer that without first turning to google. You might have screened out plenty of valid applicants with this
- pphysch 3y agoYou don't know how to transform the string "12345" to "12346" in a mainstream PL? I don't think "valid applicant" and "doesn't really grok strings/types" are compatible, outside of intern/maybe junior positions. The filter works.
- marliechiller 3y agoThe filter works perhaps for whatever niche you might be working in. I cant imagine asking this to one of my candidates and then assessing their entire professional experience off of something like this though.
- pphysch 3y agoWhat domain do you program in where handling strings/bytes is not a weekly if not daily task?
- marliechiller 3y agoThe point is not whether an applicant can or cannot do it, the point is that the question is deliberately rephrasing to obscure a candidates understanding. If you ask your average candidate to do that in laymans terms or they were given 5 seconds to google this would be a trivial task and you would have a different outcome. All this selects for is the candidate to have a working definition of an ascii decimal string in their head, it represents no ability to problem solve whatsoever.
- pphysch 3y ago> All this selects for is the candidate to have a working definition of an ascii decimal string in their head, it represents no ability to problem solve whatsoever. Problem solving isn't orthogonal to having genuine expertise. Loads of awful, brittle, hard-to-read, but working, code gets written every day by people who are good at finding a solution but haven't RTFM, so to speak.
- KaiserPro 3y agoThere is a difference between "handle this string to do a normal thing, but make it secure" and "do something stupid with this string, which goes against all good practice, oh and you can't use the obvious tools because reasons". for example, if you are using strings to do addition, why the fuck aren't you allows to to atoi? also, why are you using strings to hold numbers? everything to do with that question is something that you'd insta-reject in a diff/pr/mr. Surely converting from string to int, validating it, catching errors and generally making it nice, is a much better test? Its like going to an interview for a copywriter(someone who writes text) for safety sign company, and they ask you to make a riddle in English, but you can't use any words that are derived from Latin. Sure it shows an impressive command of both etymology and english, but its totally opposite to making clear, easy to understand text.
- kaashif 3y agoIf someone really can't do that, then either they don't know how to count (very unlikely), they didn't understand the question, or they are really bad at translating what they would do on paper into a program. All disqualifying. Another possibility is nerves. Early in my career I was very nervous in interviews and I have sympathy. I have fucked up the most basic search algorithms completely and spewed gibberish when asked to explain the complexity of my solution. I have sympathy for that, but the only way to get through interview nerves is exposure therapy. At least in my experience.
- ninkendo 3y agoEh… You’re given `99999`. Increment it. A naive approach would turn this into `9999:`. Making this work is a bit complicated and involves memory reallocation if you’re in a C-like language and you need to increase the length of the string in order to increment it. You’ll probably want a system where the caller passes a buffer of sufficient size to use for rewriting the string, in case you overflow. Make sure to have a way for the caller to pass the buffer length. You don’t want to allocate because that’s not the way it should be done in C, callers should generally allocate. You could use atoi, increment, and itoa to go back again, but that’s probably “cheating” from the perspective of a leetcode advocate, they likely want you to do this without the stdlib conversion functions. There’s a bazillion reasons why this sucks as an interview question. There’s no way a correct answer is just something you’ll “get in 15 seconds”.
- jeffbee 3y agoWhether this should be done in-place or not is a completely valid direction in which to take the discussion and would be a "pass" from me. Also a "pass" would be `return itoa(atoi(input)+1))` with relevant caveats. An O(1) in-place solution with a sane API exists in C++ and the form of it is also a handy indicator of whether candidate who proposes solving this in C++ is familiar with more recent standards or not.
- ninkendo 3y agoI don’t see how you can increment `9999` in O(1) if the string length is considered the size of the input. You have to rewrite the string with zeroes, which is O(n) of the size of the string.
- jeffbee 3y agoFor that case, which is the worst case, yes. And the amortized average complexity is O(1) because that case is unlikely. Are you starting to see why this is a good icebreaker? It has all kinds of discussion potential.
- 3y ago
- suresk 3y agoI think a lot depends on the context, the job, and the languages involved. Of course there is a trivial solution in pretty much any language, for example something like str(Decimal(x) + 1) in python. That's dead-simple and anyone should be able to do at least that. The later addendum that they want someone to know how data is store by the computer seems to imply that they want an answer that doesn't use these conversions, which gets a lot trickier depending on the context. I think you'd still expect someone who does C/C++ work to get there pretty quickly, but it is more than 15 seconds - you have to think about some corner cases and how you handle the string having to be resized in some situations. But in some languages, it isn't obvious to me how you'd do it (especially since strings are immutable in many languages) and I think it is maybe a bit unfair to ask someone who does Java or Python or whatever to do it off the top of their head.
- jeffbee 3y agoA person who isn't well-versed in how the computer represents data internally is not a "valid applicant" for the positions I interview to fill.
- hcks 3y agoWhat programs have you written?