employer cover photo
employer logo
employer logo

Clearwater Analytics (CWAN)

Engaged employer

Clearwater Analytics (CWAN) interview question

Write a function to compute a factorial n

Interview Answers

Anonymous

29 Aug 2017

Iterative: for (ii=1; n > 0; n--) ii = ii * n; return(ii); Could be to get rid of the (1 * n) iteration when ii = 1: for (ii=1; n > 1; n--) ii = ii * n; return(ii);

1

Anonymous

9 Mar 2017

def factorial(n): if n = 1 return 1 else return n * factorial (n-1); and explained how to do it without recursion.