Stuck on this problem from past few days. Someone please help me? Python 3


#1

class Solution:
# @param A : list of strings
# @return an integer
def solve(self, A):
rot = []
for i in range(len(A)):
if len(A[i]) == 1:
rot.append(1)
else:
count = 1
temp = A[i]
temp = temp[1:]+temp[0]
c=2
while temp != A[i]:
#print(temp)
count += 1
temp = temp[c:]+temp[:c]
c=(c+1)%len(A[i])
#print(c,c%len(A[i]),end=’ ')

                    rot.append(count)
            def gcd(a,b): 
                if a == 0: 
                    return b 
                return gcd(b % a, a) 
      
    # Function to return LCM of two numbers 
            #print(rot)
            l = rot[0]
            def lcm(a,b): 
                return (a*b) / gcd(a,b)
            if len(rot)>1:
                l = lcm(rot[0],rot[1])
                for i in range(2,len(rot)):
                    l = lcm(l,rot[i])
                    l = l%1000000007
            return int(l)

Please help. Working fine for each string.