I like the way you word it - it makes it sound like a form of torture.
I like the way you word it - it makes it sound like a form of torture.
The interviewer leaned in again, his tie loose, his face covered in stubble. He'd been at this for four hours now and it was showing.
"Tell us your social media passwords."
The candidate flinched back, shaking his head.
"I told you, I...that's illegal, you can't ask for those."
The interviewer clasped his hands together, cracked his knuckles, and flashed a big grin. With a swift motion he swiped a marker from the table, flicked off the cap, and stabbed it in the direction of the candidate.
"Write a linked-list implementation in C. Oh, and because you've been such a tough-guy you only get to use malloc...once. In the main function."
A bead of sweat quickly ran down the candidate's face. He looked tense, fraught with concern. The sound of his teeth grinding together wasn't hard to hear.
"S-seven salamander six exclamation three five."
Oh yeah? How about I just don't use malloc then:
static char ALLTHEFUCKINGMEMORY[1024*1024*1024];
static size_t NEXTBYTE = 0;
void *myAlloc(size_t size) {
void *ptr = &ALLTHEFUCKINGMEMORY[NEXTBYTE];
NEXTBYTE += size;
if (size & 3) NEXTBYTE = (NEXTBYTE & (~3)) + 4;
return ptr;
}
void myFree(void *ptr) {
fprintf(stderr, "REAL PROGRAMMERS DON'T NEED TO FREE MEMORY\n");
exit(-1);
}for single linked list you can just use an array of the struct and borrow/return via circular list. my C is beyond the rust levels of 20y Golf 2 but I guess I won't sweat over.
An alternative solution would be cheating away and using realloc instead of malloc.
Of course, if these were your dice rolls, you're pretty unlucky, and should try again. And/or buy a lottery ticket.