News for hackers. Stuff that matters.
Re:Getting a job at Apple without going to college or doing ... by jeffbee on Thursday August 17, 2023 @12:53PM (#37164592)
Adding 1 to an ASCII decimal strings is a great icebreaker and I always use it. It is not leetcode. It is a filter for people who have actually encountered computers before. Even though our industry is maturing there are still a huge number of candidates who present themselves without ever once having written a program. I find the question has a massive signal. Either the candidate aces it in 15 seconds, or they immediately ask a bunch of on-point clarifying questions, or they are stumped.
Re:Getting a job at Apple without going to college or doing ... by marliechiller on Thursday August 17, 2023 @01:11PM (#37164937)
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
Re:Getting a job at Apple without going to college or doing ... by jeffbee on Thursday August 17, 2023 @01:17PM (#37165035)
A 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.
Re:Getting a job at Apple without going to college or doing ... by pphysch on Thursday August 17, 2023 @01:15PM (#37165007)
You 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.

Re:Getting a job at Apple without going to college or doing ... by kaashif on Thursday August 17, 2023 @01:31PM (#37165265)
If 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.

Re:Getting a job at Apple without going to college or doing ... by marliechiller on Thursday August 17, 2023 @01:21PM (#37165096)
The 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.
Re:Getting a job at Apple without going to college or doing ... by pphysch on Thursday August 17, 2023 @01:29PM (#37165227)
What domain do you program in where handling strings/bytes is not a weekly if not daily task?
Re:Getting a job at Apple without going to college or doing ... by marliechiller on Thursday August 17, 2023 @01:36PM (#37165334)
The 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.
Re:Getting a job at Apple without going to college or doing ... by pphysch on Thursday August 17, 2023 @01:59PM (#37165636)
> 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.

Re:Getting a job at Apple without going to college or doing ... by KaiserPro on Friday August 18, 2023 @02:02PM (#37179643)
There 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.

Re:Getting a job at Apple without going to college or doing ... by ninkendo on Thursday August 17, 2023 @02:11PM (#37165775)
Eh…

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”.

Re:Getting a job at Apple without going to college or doing ... by jeffbee on Thursday August 17, 2023 @02:24PM (#37165939)
Whether 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.

Re:Getting a job at Apple without going to college or doing ... by ninkendo on Thursday August 17, 2023 @02:32PM (#37166048)
I 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.
Re:Getting a job at Apple without going to college or doing ... by jeffbee on Thursday August 17, 2023 @02:48PM (#37166246)
For 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.

Re:Getting a job at Apple without going to college or doing ... by ninkendo on Thursday August 17, 2023 @11:32PM (#37171142)
No, not when the goal is to actually implement it. You implied in your comment that if I wasn’t someone who could implement this in 15 seconds, I’m not a good candidate in your mind. It would take me longer to explain why it’s not trivial.
Re:Getting a job at Apple without going to college or doing ... by ericbarrett on Thursday August 17, 2023 @07:40PM (#37169779)
You could return the 0s with a carry flag.
Re:Getting a job at Apple without going to college or doing ... by jeffbee on Thursday August 17, 2023 @08:34PM (#37170156)
It's still O(N) even if you don't need to copy the input, because you nonetheless visited every character in the string.
Re:Getting a job at Apple without going to college or doing ... by ericbarrett on Friday August 18, 2023 @05:34AM (#37173243)
Oh, I skimmed over the O(1) part. I'm baffled then. How do you calculate an N-rune string without O(N)?
Re:Getting a job at Apple without going to college or doing ... by Aurornis on Thursday August 17, 2023 @02:53PM (#37166313)
Ironically, you just answered the "difficult" interview question in a few lines of casual commenting.

If you're not allowed to use atoi and itoa, it's still not all that difficult to do in C. Incrementing ASCII characters and handling carries is really trivial.

I'd be kind of worried if I was hiring a C developer who didn't know the basic things you described above. I'm not sure why you think those are esoteric concepts that we shouldn't expect developers to know.

Re:Getting a job at Apple without going to college or doing ... by suresk on Thursday August 17, 2023 @03:32PM (#37166773)
Your last 2 sentences highlight the crux of it, I think - in the first sentence, you say "C developer" and in the second just "developers".

This actually does seem like a great icebreaker-type question for a C developer. I'm less convinced every developer should be able to go into that level of detail if they are doing Javascript or Python or whatever. Ideally they'd be able to at least reason through some of this and demonstrate some understanding of some of this, but I'm not sure it is a great icebreaker question for all developer roles.

Re:Getting a job at Apple without going to college or doing ... by crooked-v on Thursday August 17, 2023 @05:29PM (#37168371)
Javascript doesn't even have ASCII - every string is UTF-16.
Re:Getting a job at Apple without going to college or doing ... by ninkendo on Thursday August 17, 2023 @11:28PM (#37171127)
I didn’t answer the interview question. The interview question would be to actually implement it. Something that was stated should be trivially done in 15 seconds. It would take me longer than that to explain why it’s not a trivial problem.
Re:Getting a job at Apple without going to college or doing ... by suresk on Thursday August 17, 2023 @02:40PM (#37166151)
I 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.

Re:Getting a job at Apple without going to college or doing ... by hcks on Thursday August 17, 2023 @05:30PM (#37168383)
What programs have you written?