Factorial of a given number

Beginner Problems Basic Maths Easy
  • Fun Fact: Factorial problems and algorithms are often used in real-world applications for solving problems involving permutations and combinations
  • This can be found in software related to statistics, probability, data analysis, and also in some optimization algorithms
  • For instance, Google's search algorithms use factorial calculations for providing various combinations of search results, and in machine learning, factorials play a critical role in calculating the probabilities in Bayesian Networks

You are given an integer n. Return the value of n! or n factorial.


Factorial of a number is the product of all positive integers less than or equal to that number.

Examples:

Input: n = 2

Output: 2

Explanation: 2! = 1 * 2 = 2.

Input: n = 0

Output: 1

Explanation: 0! is defined as 1.

Input: 3

Constraints

  • 0 <= n <= 10

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree