Avoid the overhead of a lambda function in recursion for DS