## ThoughtWorks Interview Question for Senior Software Development Engineers

Country: India
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
0
of 0 vote

The examples dont seem to be correct? eg. 1,2,3 can have [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3] so 7 in total

Comment hidden because of low score. Click to expand.
0

It seems correct as [2] [3] have 2 and 3 GCD resp.

Comment hidden because of low score. Click to expand.
0
of 0 vote

arr = [2,4,8,16,32,1,100007]
l = len(arr)

def memoize(f):
cache = dict()
def fn(*args):
if args in cache:
return cache[args]
else:
rv = f(*args)
cache[args] = rv
return rv
return fn

@memoize
def count(start, rungcd=None, runmax=0):
rv = 0
for nxt in range(start, l):
if arr[nxt] > runmax:
rv += count(nxt+1, gcd(rungcd, arr[nxt]), arr[nxt])
if rungcd == 1:
rv += 1
return rv

def gcd(a,b):
if a == None or a == 0:
return b
if b == None or b == 0:
return a
return gcd(max(a,b)%min(a,b), min(a,b))

count(0)

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.