I remember being shocked to discover that a recent CS grad could not implement a factorial function using recursion. I can understand why you wouldn’t want to do that, but to not be able to do it?
a lot of CS undergrads compress out recursion knowledge. They learn that most recursion is best skipped in favor of iteration/dp, and they learn that they should implement things efficiently.
It’s possible the undergrad assumed you were referring to an efficient recursive algorithm or simply forgot most recursion.
No, I was quite explicit, and seriously, is it really that hard to write something along the lines of
if (i<=1)
return i;
else
return factorial(i-1)*i;
It wasn't meant to be a trick or trap, it was the simplest recursive function I could think of and it’s not like I was asking him to implement a stack.
Heh, I just did the DS+A section of a Faang interview, and got the time and space complexity of an optimal solution more or less correct, as well as most of a recursive binary search implementation, but not quite there. I stumble with recursion because syntactically it's something you either have to use a lot or deliberately practice to have a keen sense of return values imo.
Probably won't get an offer because of that. Do I feel like as a frontend engineer I really need that knowledge? Not really. I could work it out for work purposes if I needed to tho. I'd be practicing it just to pass interviews.
I'd venture 95% of JS and Python devs don't even know what the stack is. They might have some vague understanding of a reference type vs. a value type, but that's probably it. Even in something like C# or Java I'd guess it's less than half that know what they are.
Example, most programmers I know have no idea when a variable gets allocated on the stack and when it's on the heap.
Let's not talk about how many dont even know what a (stack overflow)[https://en.m.wikipedia.org/wiki/Stack_buffer_overflow] is...