Live data from Hacker News

The four programming questions from my 1994 Microsoft internship interview (2023)

computerenhance.com

101–103 of 103 posts

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#101
post #72

My first ever programming interview was like a group interview. There were three or four programmers asking me questions, one at a time. The only one I remember was to check if two strings were equal (in C). I wrote (maybe buggy) code to iterate both pointers, comparing while looking for the null terminator. The interviewer stopped me and said, “You should compare their lengths first. If they are different, you can e…

"Group interviews" produce horrible, unfair dynamics.

Snapping with know-it-all arrogance is toxic and doesn't help anyone. You were correct because strcmp has to iterate both strings, just like strlen would.. and it's totally pointless.

    #include 
    /* C89 and handles NULL and overlapping strings */
    int strequal(const char *a, const char *b) {
            return (a == b || (a != NULL && b != NULL && strcmp(a, b) == 0));
    }
I think you dodged several bullets by not getting hired there because they sounded insufferable.

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#102
post #72

My first ever programming interview was like a group interview. There were three or four programmers asking me questions, one at a time. The only one I remember was to check if two strings were equal (in C). I wrote (maybe buggy) code to iterate both pointers, comparing while looking for the null terminator. The interviewer stopped me and said, “You should compare their lengths first. If they are different, you can e…

C is pretty bizarre but I expect someone writing it professionally to know that even passing void compareStrings(char str1[], char str2[]) is equivalent to compareStrings(char * str1, char * str2) so no way to get the length of it with sizeof(str1) and strlen walks the string until it finds the null terminator.

No, it's not bizarre, it's standardized on what is and isn't UB based on history, and usually for performance.

NUL-terminated strings don't know their lengths and so, without an "n" variant function and running strlen() ahead-of-time, must iterate the entire thing. Pascal format strings (supported up to 255 byte lengths in the classic form) could find length as an O(1) operation because there was no terminator necessarily.

Re: The four programming questions from my 1994 Microsoft internship interview (2023)

#103

Earlier quoted context omitted.

C is pretty bizarre but I expect someone writing it professionally to know that even passing void compareStrings(char str1[], char str2[]) is equivalent to compareStrings(char * str1, char * str2) so no way to get the length of it with sizeof(str1) and strlen walks the string until it finds the null terminator.

No, it's not bizarre, it's standardized on what is and isn't UB based on history, and usually for performance. NUL-terminated strings don't know their lengths and so, without an "n" variant function and running strlen() ahead-of-time, must iterate the entire thing. Pascal format strings (supported up to 255 byte lengths in the classic form) could find length as an O(1) operation because there was no terminator necess…

It is bizarre. C is bizarre, there is no string type and there should've been a string type. scanf is an invitation for buffer overflow attacks. I know how poorly designed languages look like and C despite its strengths is still a poorly designed language.
Post reply on HN