Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlintailrec functionsSingle-choice MCQ

Why does this `tailrec` function compile and run without a stack overflow for large `n`, and what would break the optimization?

tailrec fun factorial(n: Long, acc: Long = 1L): Long { return if (n <= 1L) acc else factorial(n - 1, acc * n) }