+ 4
Anyone can help to optimize my code. How can i reduce the time complexity and memory problem.
Here is my code zeroth case is susccessfully executing but after that all cases are failing am getting proper output but it showing memory exceed problem https://code.sololearn.com/ca10A0A5A236
7 Answers
+ 4
A.S.
Python seems to work like a charm because of its big data ability.
While for c++, the data type cannot hold big value like factorial of 21.
edit:
I just visited the hackerank link that you've provided above. And its looks like the challenge is totally different. But still has got to do with finding the big factorial efficiently, so you can check the factorial function from the code below and play with it and hopefully the challenge gets solved.
https://code.sololearn.com/cKcpjYm0Ys6n/?ref=app
Python version:
# return factorial using memoization
mo = {1:1}
def fact(n):
global mo
if n in mo: return mo[n]
if n<=1: f=1
else: f=n*fact(n-1)
mo[n]=f
return f
e = 0
for n in range(50):
e += 1/fact(n)
print(e)
+ 3
A.S. Oof... I can't even bother to try to read such cryptic named functions. You should also be trying to write code that makes sense and is easy to read.
Good luck. Hopefully someone else is up for the challenge deciphering this code.
+ 1
Can you tell the description of the assignment?
+ 1
e = Summation(1/n!) as n tends from 0 to infinity?
Is this code of yours trying to find the value of euler number "e"?
+ 1
rkk yeah its hackarrank Question before i did another code but it was much more complex so i changed my logics i made step by step i know its ugly but
0
rkk its not working should i need to use char array data will be store in form of strings then i will convert on int