We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 9: Recursion 3

Day 9: Recursion 3

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 9: Recursion 3
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial
  • Tutorial

Objective
Today, we are learning about an algorithmic concept called recursion. Check out the Tutorial tab for learning materials and an instructional video.

Recursive Method for Calculating Factorial

Function Description
Complete the factorial function in the editor below. Be sure to use recursion.

factorial has the following paramter:

  • int n: an integer

Returns

  • int: the factorial of

Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of .

Input Format

A single integer, (the argument to pass to factorial).

Constraints

  • Your submission must contain a recursive function named factorial.

Sample Input

3

Sample Output

6

Explanation

Consider the following steps. After the recursive calls from step 1 to 3, results are accumulated from step 3 to 1.

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy