I was given this coding question in interview:
given a very very large number (say more than long or any in-built types) print out its factorial. you can not assume a max limit anywhere in the program.I had to make a working code on computer and during interview.
I am really curious, how long on average would it take for others?
this is subjective question but an average will set some ballpark figures and a benchmarks for such a coding question.
What I did?
I chose C and represented number by a linked list of characters (containing a single digit). though perhaps it can be made more efficient to store chunks in int/long and do int arithmetic than store it in chunk of characters.
I took 2 hours and spat out a code with things in place, major fns coded, but then interviewer said she wanted a completely working one and asked me to do it offline and mail it to her.
The good solution is to write a BigInt class that supports addition and mutilplication only. The number shouldn’t be kept in base 10, rather in base 10000, i.e. each digit is a number 0-9999. Writing this is about 50-60 lines of code which should be relatively quick. I would also go with vector rather than list
Of course if you’re not allowed to use an existing big int class.