Hello, welcome to
Inter-Dot Web Solutions!
I’m Maria, and I’ll be
conducting your technical
screen interview today.
Slide 3
Slide 3 text
Thanks, I’m excited to be here and ready
to jump into the technical interview!
Slide 4
Slide 4 text
Let’s jump right in, then.
I’m going to give you a
single function, and we’ll
use that function
throughout the interview.
Slide 5
Slide 5 text
No content
Slide 6
Slide 6 text
Can you tell me what this
function does?
Can you write some code
that uses it?
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
Fantastic, well done!
Now, what if we wanted
to compose more than two
functions, like this?
Slide 9
Slide 9 text
No content
Slide 10
Slide 10 text
Could we do that by using
ONLY the “composeTwo”
function?
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
Great.
But is there another way
you could use
“composeTwo” to express
the composition?
Slide 13
Slide 13 text
…hmmmm…
Slide 14
Slide 14 text
Ah! Function composition is associative,
so we can do this instead…
Slide 15
Slide 15 text
No content
Slide 16
Slide 16 text
Indeed, nice.
“f”, “g”, and “h” functions
all produce the same
output. But are they the
same kind or shape?
Slide 17
Slide 17 text
…hmmmm…
Slide 18
Slide 18 text
We can use equational reasoning to
substitute the definition of “composeTwo”
inline, and compare.
Slide 19
Slide 19 text
No content
Slide 20
Slide 20 text
What do we know about
the differences between
how “f” would execute
compared to either “g” or
“h”?
Slide 21
Slide 21 text
“f” will have a call-stack depth of just 2,
but both “g” and “h” will have call-stack
depth of 3.
Slide 22
Slide 22 text
You’re doing great!
Now let’s add in a fourth
function as part of the
composition.
Slide 23
Slide 23 text
No content
Slide 24
Slide 24 text
Seems like it’s going to
become very cumbersome
to keep nesting calls to
“composeTwo” as we add
more steps to the
composition.
Slide 25
Slide 25 text
Any ideas on how we could
define a “compose”
function using
“composeTwo”, but which
can compose as many
functions as we need?
Slide 26
Slide 26 text
I think so.
Slide 27
Slide 27 text
No content
Slide 28
Slide 28 text
Can you explain that?
Slide 29
Slide 29 text
Looping through the function arguments
in reverse, and for each iteration
defining a new “f” that is the composition
of the previous “f” and the preceding
function argument.
Slide 30
Slide 30 text
Instead of looping
through the function
arguments in reverse,
could you loop forward
and still compose?
Slide 31
Slide 31 text
Associativity to the rescue, again!
Slide 32
Slide 32 text
No content
Slide 33
Slide 33 text
Wonderful.
And just like before, what
are the differences in
shape of these?
Slide 34
Slide 34 text
No content
Slide 35
Slide 35 text
But now the call-stack depth is 4 for
both “g” and “h”, whereas it’s still just 2
for your “f”.
Slide 36
Slide 36 text
These loops you’ve written,
they look like reductions
to me.
Can you express them
with reduce utilities?
Slide 37
Slide 37 text
No content
Slide 38
Slide 38 text
Impressive!
And the shapes of these
functions?
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
Same shapes, respectively. And same
call-stack depth of 4.
Slide 41
Slide 41 text
Interesting.
Instead of loops, let’s try
recursion.
Slide 42
Slide 42 text
No content
Slide 43
Slide 43 text
Yet again, same shapes and same
call-stack depth of 4.
Slide 44
Slide 44 text
Huh. Usually linear
loop-based algorithms end
up with lower call-stack
depth than recursive
algorithms, but not here.
Slide 45
Slide 45 text
Any idea how we could
make a definition for the
general “compose” that
doesn’t have the higher
call-stack depth?
Slide 46
Slide 46 text
…hmmmm…
Slide 47
Slide 47 text
I think the problem is that by using the
“composeTwo” function, we’re lazily
deferring the actual function calls.
Slide 48
Slide 48 text
Instead, if we eagerly compute each
intermediate composition result, and
then pass that onto the next, it should
keep the max call-stack depth at 2.
Slide 49
Slide 49 text
OK, that sounds good.
Can you do that with
loops, reductions, AND
recursion?
Slide 50
Slide 50 text
No content
Slide 51
Slide 51 text
Amazing.
But what are the shapes
of those functions?
Slide 52
Slide 52 text
No content
Slide 53
Slide 53 text
The loop and reduction implementations
are now call-stack depth of 2. But the
recursion one is still call-stack depth of 4.
Slide 54
Slide 54 text
Perfect.
Well, I have to say, you
breezed through this
technical screen
interview. We’ll be in
touch!