Recursion vs Iteration ā Kai vs Tek | FLT Debates
š Full written solution: https://interview-kit-fe.vercel.app/vsraj-recursion-vs-iteration š» Code on GitHub: https://github.com/timepasshub2539-hue/leetcode-python/tree/main/vsraj-recursion-vs-iteration Chapters: 0:00 Recursion vs Iteration 0:10 The Call Stack Grows 0:24 Iteration Reuses One Frame 0:34 Why Use Recursion 0:41 The Problem With Loops 0:51 When To Use Recursion 1:07 Tail Call Optimization 1:41 Recursion vs Iteration Decision Kai and Tek argue over recursion vs iteration: why the call stack physically grows with every recursive call, how iteration reuses one frame instead, and why recursion still earns its place in real code. They break down the real decision rule for picking one over the other, plus why tail-call optimization isn't the safety net most people assume. #recursion #iteration #computerscience #codinginterview #datastructures Watch next: - Quick Quiz! #shorts: https://youtu.be/4OGx0MYg5BQ - 3116. Kth Smallest Amount With Single Denomination Combination: https://youtu.be/EYU3-J_YFkg - The Bug That Loses Money #shorts: https://youtu.be/4yI65id75W4
The solution
def factorial(n, acc=1):
if n == 0:
return acc
return factorial(n - 1, n * acc) # tail callReady to try it yourself? Solve Stack problems with instant feedback in the practice sandbox.
Practice now ā


