4 ms·
I interviewed for an internship in 2006 and didn't get any brainteasers, but I got some pretty interesting questions that were somewhat computer science-related
by vecter 2mo ago
I interviewed for an internship in 2006 and didn't get any brainteasers, but I got some pretty interesting questions that were somewhat computer science-related:
1. Suppose you have a binary tree (NOT a binary search tree) where each node with pointers to its parent and children. Given pointers to two arbitrary nodes in the tree, find their lowest common ancestor.
2. My favorite: given a uniform random number generator mod 5, create a uniform random number generator mod 7
3. Forgot the exact question, but something along the lines of: suppose you want to keep track of function arguments as you call them. How do you do that?
I got (1) and (2) and utterly failed (3). (3) is entirely trivial and basically a stated fact if you know how anything about how operating systems work, but I was a freshman in college and didn't know that function arguments got pushed on a stack in memory, so I was totally lost.
- leni536 2mo agoI would assign (3) to language runtimes and calling conventions rather than operating systems.
- dcrazy 2mo agoFWIW, in most architectures the first few function arguments get passed in registers. But so many of today’s programmers grew up with 32-bit x86, which has a paucity of registers, that they mentally shortcut to “every argument gets passed on the stack”. Nowadays, with x64 and AArch64, the first several arguments will be passed in integer or floating-point registers.