Pregunta de entrevista de Rewards Network

How to do safe recursion in Scala?