ThoughtWorks Interview Question for Senior Software Development Engineers

Country: India
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
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

- Anonymous June 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 votes

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

- Anonymous July 01, 2016 | Flag
Comment hidden because of low score. Click to expand.
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]
rv = f(*args)
cache[args] = rv
return rv
return fn

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))


- Anonymous July 03, 2016 | Flag Reply

Add a Comment

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


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

Learn More


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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More