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

Aug 29, 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

Mar 9, 2017

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