## Facebook Interview Question

Software Engineers**Country:**United States

**Interview Type:**In-Person

```
def factors(n):
f=[]
for i in range(1,n):
if n%i==0:
f.append(i)
return f
def periodic(s):
f=factors(len(s))
for i in f:
m=len(s)/i
#return s[:i]*3
if s[:i]*int(m)==s:
return True
return False
print(periodic('abcabc'))
def factors(n):
f=[]
for i in range(1,n):
if n%i==0:
f.append(i)
return f
def periodic(s):
f=factors(len(s))
for i in f:
m=len(s)/i
#return s[:i]*3
if s[:i]*int(m)==s:
return True
return False
```

What am I missing about example number 2 in the question:

S = "xxxxxx", n = 1, then P = "x"

This doesn't seem consistent with the other examples.

In the first example, if n=3 and P=ab, then 3ab => ababab, that makes sense.

In the third example, if n = 2 and P=aabba, then 2aabba => aabbaaabba, that make sense.

But for exmple 2, if n=1 and P=x, then 1x should be x, not xxxxxx. I feel that in this case, if the P is x, then n should be 6, because 6x => xxxxxx

What am I missing? Am I fundamentally misunderstanding the problem here?

a slightly improved version

```
#!/usr/bin/env python3
"""
Find whether string S is periodic. Periodic indicates S = nP. e.g.
if S = abcabc, then n = 3, and P = abc
if S = xxxx, n = 1, and P = x
follow up, given string S, find out repetitive pattern of P
"""
def factors(n):
f = []
for i in range(1, n):
if n % i == 0:
f.append(i)
return f
def periodic(s):
f = factors(len(s))
for i in f:
m = len(s)/i
if s[:i] * int(m) == s:
print(i, s[:i], s)
return True
return False
# driver
if __name__ == "__main__":
assert True == periodic('abcabc')
assert False == periodic('abcabcd')
```

Looking for interview experience sharing and mentors?

- acoding167 June 07, 2019Visit A++ Coding Bootcamp at aonecode.com.

Taught by experienced engineers/interviewers from FB, Google and Uber,

our ONE TO ONE courses cover everything in an interview including

latest interview questions sorted by companies,

SYSTEM DESIGN Courses (highly recommended for people interviewing with FLAG)

ALGORITHMS (conquer DP, Graph, Greed and other advanced algo problems),

and mock interviews.

Our students got offers from Google, Uber, Facebook, Amazon and other top companies after a few weeks of training.

Welcome to email us with any questions. Thanks for reading.