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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 9: Recursion 3
  5. Discussions

Day 9: Recursion 3

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 1014 Discussions, By:

votes

Please Login in order to post a comment

  • RISHAV_SHARMA
    6 years ago+ 22 comments

    Use Function name as "factorial" rather to use any other like f or fact.

    After that your all testcase will be pass.

    73|
    Permalink
    View more Comments..
  • n_okroshiashvili
    4 years ago+ 13 comments

    In Python 3.

    We know that factorial of 1 and 0 is 1, after that we have what we have

    def factorial(n):
        if n <= 1:
            return 1
        else:
            result = n * factorial(n - 1)
            return result
            
    
    36|
    Permalink
    View more Comments..
  • vikasgothwal0
    6 years ago+ 4 comments
    factorial = lambda x : 1 if x<=1 else x*factorial(x-1)
    print(factorial(int(input())))
    
    29|
    Permalink
    View more Comments..
  • aleksandrhovhan1
    6 years ago+ 6 comments

    Here's my simple solution in Java:

    import java.util.*;
    
    public class Solution 
    {
    
        public static void main(String[] args) 
        {
            Scanner scan = new Scanner(System.in);
            System.out.println( factorial(scan.nextInt()) );
        }
            
        public static long factorial( int n )
        {
            return (n == 1) ? 1 : n*factorial(n-1) ;
        }
    }
    
    21|
    Permalink
    View more Comments..
  • michal_skvor
    6 years ago+ 11 comments

    The computed values is printed properly, the function has the name factorial and it fails with this message:

    Traceback (most recent call last):
      File "/custom-E0P65VURzzcASfYoaTsm/solution.py", line 69, in <module>
        data["signals"] = map( int, open( "signal00.sig" ).read().strip().split() )
    IOError: [Errno 2] No such file or directory: 'signal00.sig'
    

    What is wrong?

    9|
    Permalink
    View more Comments..
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature