[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I just failed a technical interview and they won't tell

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 114
Thread images: 18

File: q10.png (39KB, 719x395px) Image search: [Google]
q10.png
39KB, 719x395px
Can you solve these questions? It's a big company in the news a lot and I didn't have to sign an NDA. If you tell me the answers I'll tell you the company.
>>
File: q1.png (44KB, 719x419px) Image search: [Google]
q1.png
44KB, 719x419px
>>
File: q2.png (34KB, 719x335px) Image search: [Google]
q2.png
34KB, 719x335px
>>
File: q3.png (38KB, 719x347px) Image search: [Google]
q3.png
38KB, 719x347px
>>
File: q4.png (29KB, 719x299px) Image search: [Google]
q4.png
29KB, 719x299px
>>
File: q5.png (32KB, 719x359px) Image search: [Google]
q5.png
32KB, 719x359px
>>
File: q6.png (58KB, 719x563px) Image search: [Google]
q6.png
58KB, 719x563px
>>
>>60098940
Offbyone
>>60099001
Corruption
>>60099014
Null ptr
>>60099031
Looks good

Toast me
>>
File: q7.png (35KB, 719x419px) Image search: [Google]
q7.png
35KB, 719x419px
>>
>>60098940
Why the fuck are you copying the array just to print it out?
>2 * rgArray[i]
What the fuck is this? I don't see this an an answer?
I don't think I'd want to work for this company.

I'm not even going to read the rest.
>>
File: q8.png (29KB, 719x263px) Image search: [Google]
q8.png
29KB, 719x263px
posting new images takes too fucking long.
>>
File: q9.png (35KB, 719x347px) Image search: [Google]
q9.png
35KB, 719x347px
There's 10 total questions btw. This is the last one.
>>
>>60098940

My answers were

question01: B
question02: F
question03: G
question04: B
question05: E
question06: G
question07: E
question08: G
question09: G
question10: B

Revel in my ignorance.
>>
>>60099094

how the hell is >>60099001 stack memory corruption? I assumed it would be from heap memory. fuck.
>>
>>60099207
malloc gives you heap memory
initialising something like this[1024]; places it on the stack
only space for 1024 characters is reserved, if the string was longer it would go past that and fuk shit up
>>
Why are ALL these functions creating a temporary buffer for no reason?
>>
>>60098940

>
*(ptrMyArray+i)

why

Anyway OP, why don't you supply your answers?
>>
>>60099105
Printing something is usually done as a substitute for actual work in a function. It's so the exercise doesn't complicate the code more than it should beside the goal.
>>
>>60098940
I believe it's the <= in the for loops that would cause it to assign something outside allocated memory. Should be <

I think.
>>
>>60099105
>double all values
>>
>>60099014
>>60099094
Looks fine to me. nCount can overflow if it gets too high I guess.
>>
>>60098940
>H) Yes, possible integer overflow
think outside of the box
>>
File: 1402028778574.jpg (140KB, 778x1018px) Image search: [Google]
1402028778574.jpg
140KB, 778x1018px
>>60098940
><=

if you didn't catch that, i bet they threw you into le garbage instantly
>>
>>60099457
I did

question01: B
question02: F
question03: G
question04: B
question05: E
question06: G
question07: E
question08: G
question09: G
question10: B
>>
File: Weisswandtafel.jpg (14KB, 600x691px) Image search: [Google]
Weisswandtafel.jpg
14KB, 600x691px
Were there any whiteboards in the interview, anon?
>>
>>60099252
This is C++: dynamically sized arrays are declared with "new" and allocated in the heap.
>>
>>60099048
Off by one error. This can assign a 0 outside the range specified.
>>
>>60098940
>int* ptrMyArray = new int[nSize];
This would not compile.
>>
File: 1493306537112.png (18KB, 576x422px) Image search: [Google]
1493306537112.png
18KB, 576x422px
>>60099801
Don't bring this up ever again.
>>
>>60098940
I'm glad I only program as a hobby. I don't know if my code works until I run it. I would definitely fail if someone asked me to look at code and point out any errors.
>>
>>60098940
b: i <= nSize
c: fixed length temp[1024]
f: int nCount;
d: malloc could fail, doesn't check
b: nIndex == nSize and increment afterwards
e: infinite loop if nSize < 0 passed (will actually stop eventually after rollover), else g but result might overflow as well
g
e: bKeepGoing = true
g
g
>>
>>60099837
Why not?
>>
>>60099014
F, nCount isn't initialized to 0, but maybe I'm dumb and C++ sets variables to 0 by default?
>>
>>60100574
>C++ sets variables to 0 by default?
It most definitely doesn't.
>>
>>60100683
It does in a new process. By default Windows and Unix will zero out a new address space for you. So you can safely assume the very first initializarion is 0, however any subsequent calls init'ing local vars may not have 0's.
>>
>>60098940
>unsafe langauge
That is where these examples are wrong.
>>
>>60100788

No, fuck you or post the source of your ridiculous claims. It doesn't work like that and it never has.
>>
>>60099031
If malloc fails there could go stuff wrong right?

>>60099062
possible off by one
>>
>>60098940
>C but with classes
>>
File: kazemori.jpg (559KB, 955x1350px) Image search: [Google]
kazemori.jpg
559KB, 955x1350px
OP here the company in question is Hot Topic in Phoenix AZ. I'm trying to impress this girl working there by answering these questions for her.
>>
>>60099079
possible memory leak. If fopen("out.jpg" returns null, the function returns -1 before freeing memory
>>
>>60101321
so this isnt for you?
>also pic of grill?
>>
File: 1428092353038.jpg (171KB, 800x600px) Image search: [Google]
1428092353038.jpg
171KB, 800x600px
The major error all of these have in common is that the fellow programmer expects you to clean up after his shit. Do your own fucking work, scrub. I have stuff to do too, you know? We have deadlines. Stop bugging me with trivial shit. Why are you in my office anyway? HAVE YOU EVEN TRIED COMPILING? READ THE FUCKING ERROR MESSAGES
>>
For the first one, it is C) because *(ptrMyArray+i) causes memory leak on ints in ur array why are u using +i bruh

nvm im retard
>>
>>60101491
it's called pointer arithmetic
>>
>>60101491

*(ptrMyArray+i) and ptrMyArray[i] have the exact same meaning
>>
>>60101569
so does i[ptrMyArray]
:^)
>>
>>60099098
Don't see anything wrong, I might be dumb though

>>60099125
What happens if user gives negative nSize here, do possibilities like these count, I don't even

Also
>all of questions
>assuming your coworkers gender
>he or she
>not using the all the pronouns like zhe
>not knowing there are 56 genders
Trust me op you don't want to work for this bigoted company
>>
>>60101651
no that just means you're retarded
>>
The real answer is to stop doing all this unsafe array[N]/raw pointer shit and give that retard a C++ book from this century.
>>
>>60098940
for loops should be nSize-1
>>60099001
doesn't check if pointer resolves to anything before starting
>>60099014
doesn't check if nSize is positive
>>60099031
I think it's ok but am example of retardation
>>60099048
should be nSize-1
>>60099079
this looks ok, assuming delete [] is a real thing c++ can do
>>60099062
depends if you assume nSize is always accurate. If so off by one, if not memory corruption and infinite loop as well
>>60099098
works but really should be a for loop
>>60099114
I see nothing wrong and it's even readable
>>60099125
I don't know c++

t. jspfag who hasn't touched c/c++ in 10 years
>>
>>60101651

*(int* + int) = *(int*) = int
int*[int] = int
int[int*] is not valid
>>
My C autism is tingling.

>>60099031
This one is actually null pointer dereference, since the return value of malloc isn't checked, and malloc will return null if the allocation failed.
>>
File: pic_g_book_animu.png (350KB, 500x492px) Image search: [Google]
pic_g_book_animu.png
350KB, 500x492px
>>60099098
Now that's an infinite loop, desu.
>>
>>60101703
>doesn't check if nSize is positive
No. The code is correct. The documentation made it clearly that nSize must be positive. nSize == 0 could be discussed.
>>
Thanks for answering everyone. The company is Space x.
>>
>>60102651
Was this some online assignment or what?
>>
>>60102673
No. I failed that test yesterday. I don't expect to get hired by them later so meh. I need to get better for my other upcoming interviews which is why I need to know how I screwed up on this one.

The worst part is that this is the first barrier to entry before I could do a phone interview. I'm not even good enough to pass it.
>>
>>60101111
> fuck you or post the source of your ridiculous claims
Linux kernel does the same. Now learn the basics of OS design kay.

https://blogs.msdn.microsoft.com/tims/2010/10/29/pdc10-mysteries-of-windows-memory-management-revealed-part-two/
> As a process demands memory, it is faulted in from the zero page list [..] Firstly, the zero page thread runs at the lowest priority and is responsible for zeroing out free pages before moving them to the zeroed page list
>>
>>60102651
Are you fucking kidding me? was it for QA or some other bullshit position, or actually SDE? those questions were too simple

Fucking shit, you would expect they were using SPARK, not codemonkey C++.... I mean, COME ON, it's fucking 2017!
>>
>>60103708
You don't seem to understand that practical languages with lots of users trump special snowflake stuff any day of the week for production purposes. C++ is fast, a lot of people know it and there's lots of very well tested libraries that go along with it.

Also, I said two post above yours that this was the barrier for entry, this is before someone even gets phone screened.
>>
>>60103708
In addition, I only had 45 minutes to solve them all.
>>
>>60099817
Congrats, you're clinically retarded.
>>
>>60101456
None of them would have any error messages or compilation issues. Most would even work in most, if not all realistic, scenarios (but fail in edge cases anyway). You're literally more incompetent than OP, who is objectively retarded.
>>
>>60102651
Good thing you failed then desu.
You don't want to work for a charlatan (Musk) who severely underpays his workforce because he deludes them into thinking they are progressing humanity.
Honestly working for Amazon sounds more bearable from what I've heard. Fucking Amazon.
>>
>>60099062
Ignore the other guys I'm 99% sure this is fine
>>
>>60104029
Thanks for letting me know that I suck. I will try to improve.
>>
>>60101678
>>60101729
Do you niggers even C?

#include <stdio.h>

int main(int argc, char **argv)
{
int a[] = {1, 2};
printf("%d == %d\n", a[1], 1[a]);
return 0;
}


Explain this.
>>
>>60101655
while (bKeepGoing = true) will set keepgoing to true instead of comparing and loop forever
>>
>>60099125
if you don't have enough memory malloc will return null and you'll have a null pointer dereference, but other than that it looks fine
>>
Is there exercises like this elsewhere? Like on a book or something?
>>
>>60098940
>has asked you to look over a function
yes, that's not a function
>>
File: tumblr_nafcpd2lva1rea9plo1_1280.png (211KB, 512x384px) Image search: [Google]
tumblr_nafcpd2lva1rea9plo1_1280.png
211KB, 512x384px
>>60104305

Okay, so what is the company, then?
>>
>>60098940
people writing C++ needs to learn unit testing is what I see when I read code like this
>>
>>60103708
>Are you fucking kidding me? was it for QA or some other bullshit position, or actually SDE? those questions were too simple

You know that blog post about how most college graduates and software developers can't do fizzbuzz? It isn't a joke.
>>
>>60099094
>>60099014
Actually it is use of uninitialized local variable, he checks for null pointer dereference. nCount can be anything so it won't return the number of times a number greater than nThreshold is present, it will return random values + number of times a number greater than nThreshold is present.
>>
>>60099062
>>60104292
but if nSize is negative, its a possible infinite loop

other questions check if nSize is negative and do nothing or return a error
>>
>>60104606

I'm beyond fizz buzz capabilities but some of these still stumped me. I seriously think you underestimate how much working in an environment that exposes you to these edge cases helps. Everyone if I've done tons of leet code it's still left a gap.

I'm not too sure how to fix it aside tbqh.
>>
>>60099114
D.) Forgot to check if ptrHaystack is a null pointer
>>
>>60099839
>>60099801
What is this meme?
>>
>>60101456
stupid frog poster
>>
>>60099001
is this wrong because ptrString could be more than 1024 characters long, and so the for loop would smash the stack? ie memory corruption?
>>
OP thanks for posting these. making me brush up on my C
>>
>>60098940
easy off by one: <= rather than <.
>>
File: Untitled-1.png (49KB, 719x395px) Image search: [Google]
Untitled-1.png
49KB, 719x395px
>>60098940

Here OP, I did your homework
>>
>>60098940
B

>>60099001
C

>>60099014
F

>>60099031
D, but in the real world you'd just let it crash, since if you're OOM you're fucked anyway, it's a personal G from me

>>60099048
B

>>60099062
nSize has to be positive, I'd say they want you to answer E, but really, in the real world it'd be a size_t and a <


---

I'm stopping here, this is too retarded
>>
>>60099094
>Looks good
Nope.
Return value of malloc is not checked. It's a null pointer dereference.
>>
>>60099817
You're a fucking idiot.
>>
>>60099062
This code is erroneous but none of the options fit it.
He's not checking that nSize is larger than 0.
>>
>>60105186
>its a possible infinite loop
Wrong. It'll wrap around at some point and terminate.
>>
>>60098940
My best reading is
Q1
> Memory corruption, you can't trust user input to be properly terminated
Q2
> Uninitialized variable nCount
Q3
> Good, but others pointed out malloc fail
Q4
> Off by one
Q5
> Proper, I wouldn't say negative size is enough to count it wrong
Q6
> Memory leak on failed open
Q7
> '=' instead of '==', infinite loop
Q8
> Null pointer dereference
Q9
> Glorious proper C
Q10
> Off by one, '<=' should be '<'
>>
>>60104081
+1
>>
Sorry Sir but I code only Javascript.
>>
>>60098940
Am I horribly miss-remembering C or wouldn't *(ptrMyArray+i) create problems there since new integer begins every 4 bytes, so it should be ptrMyArray + (i * sizeofint) instead?
>>
>>60099738
I found this one actually to be a harder one since it's so easily overlooked. And if you start seeing the possibility that some languages start from 1 (like lua) it might be easily ignored.

Once it throws an error though it's easy to spot whats wrong.
>>
>>60098940
>hit compile button
>get a list of errors
ez
>>
>>60111202
>babby's first deployment
>>
>>60104354
Wtf, I can only guess it replaces the expression by *(ptr + x) so *(x + ptr) would be the same.

It prob should not compile though since it's fucking weird.
>>
>>60109927
> Am I horribly miss-remembering C
This.
>>
Is there anything more awful than the "find the error in someone elses code"?
>>
>>60098940
Certain off by one error at i<=nSize.
Also unnecessary if(!ptrMyArray) return;
>>
>>60111443
The only applicable test of programming knowledge is writing code on a real computer with a real internet connection.
>>
>>60111480
>>60111443
I think those find error in someone's code are fine. They did weed out OP, after all. Surely magnitudes better than writing code on paper.
>>
>>60111202
They all compile.
>>
>>60104354
Check out my 3 dimensional array notations, all the same.
(*aPtr)[3][1]
3[*aPtr][1]
*(*(*(aPtr)+3)+1)
*(*(*aPtr+3)+1)

I used this one, 3[*aPtr][1]
>>
>>60098940
Here's a fucking error: Using humans instead of linters, it's basically an instant disqualification for me ever wanting to work there.
>>
>>60104354
>>60111209
>>60111543
Why stop there?

char e=1["hello"];
>>
>>60098940
>tfw don't get any of these questions
>tfw forever a javadrone
>>
>>60111209
It compiles and thats how the '[ ]' notation works in C.
C syntax can be really weird sometimes and C obfuscation competitions exists for that reason.
>>
>>60111209
If I remember correctly it's because if a[1] means "address of 'a' plus 1" then 1[a] means "1 plus the address of 'a'" which are equivalent.
>>
>>60106806
>What is this meme?

guy bitched on twitter because Google wouldn't hire him for not being able to reverse a binary tree on a whiteboard, despite Google using his software for years.
>>
>>60099048
Negative nSize causes infinite loop. Bad loop condition.
>>
>>60099062
Whoops meant this one
>>60112093
>>
>>60112065
Oh right. Homebrew is shit, though. Convenient but shit.
Thread posts: 114
Thread images: 18


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.