HackerRank Solution: Sherlock and GCD

Sakshi Singh
1 min readJun 28, 2019

--

In python3

#In this find the GCD of the given elements in list ‘a’ if its gcd is 1, it means there is no element which can divide all. Hence, it contains a subset

# Complete the solve function below.
def solve(a):
res = a[0]
for i in range(1,len(a)):
res = math.gcd(a[i],res)
if(res != 1):
return ‘NO’
else:
return ‘YES’

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sakshi Singh
Sakshi Singh

Responses (1)

Write a response