Unit 1 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
n
always be a positive integer?
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Create a function that calculates the factorial of a positive integer n
.
1) Create and initialize a variable to store the result
2) For each number from 1 to n, multiply the result by that number
3) Return the result variable
⚠️ Common Mistakes
def factorial(n):
result = 1
for num in range(1, n + 1):
result *= num
return result