Blibli Interview Question

Recursive Problem and logic algorithm with a most efficient solution