Amazon Frontend SDE interview question

Kapil Thukral
Sep 10, 2021

--

Problem: define a sum function such that: sum(1,2,3)(4,10)() returns 20 and sum(1)(2)(3)() returns 6 and sum(1,2,3,4,5)(1,2,3)(1,10)() returns 32.

Note: last function call is always empty without any arguments passed in.

Approach: Keep accumulating all the arguments that are passed in and at last execute the sum function whenever we get () “function call with zero arguments”

--

--