GlobalLogic Interview Question

they asked me to write some codes using recursion.