## 作者：Hanyu、Leon     编译：1+1=6

“You’re speaking our language. Up for a challenge?”

• level 1和level 2 的题目十分简单，每个题目会给 24–48个小时 的做答时间，考的主要是一些 基础的编程概念

• level 3 会考一些 简单的算法 ，每个题目会给 96个小时 的做答时间；

• level 4 的题目就比较难了，会考一些不常见的算法。

Commander Lambda has had an incredibly successful week: she completed the first test run of her LAMBCHOP doomsday device, she captured six key members of the Bunny Rebellion, and she beat her personal high score in Tetris. To celebrate, she’s ordered cake for everyone – even the lowliest of minions! But competition among minions is fierce, and if you don’t cut  exactly equal slices of cake for everyone, you’ll get in big trouble.

The cake is round, and decorated with M&Ms in a circle around the edge. But while the rest of the cake is uniform, the M&Ms are not: there are multiple colors, and every minion must get exactly the same sequence of M&Ms. Commander Lambda hates waste and will not tolerate any leftovers, so you also want to make sure you can serve the entire cake.

To help you best cut the cake, you have turned the sequence of colors of the M&Ms on the cake into a string: each possible letter (between a and z) corresponds to a unique color, and the sequence of M&Ms is given clockwise (the decorations form a circle around the outer edge of the cake).

Write a function called solution(s) that, given a non-empty string less than 200 characters in length describing the sequence of M&Ms, returns the maximum number of equal parts that can be cut from the cake without leaving any leftovers.

def solution(s):
sub = s[0:len(set(s))]
return(s.count(sub))
print(solution('abcabcabcabc'))
>> 4
print(solution('abccbaabccba'))
>> 2


def solution(s):
if (len(s) % 2 != 0):
print('Odd')
else:
print('Even')

solution('abcabcN')
>> ODD
solution('abcabc')
>> EVEN


• 取余运算 在计算商值时 商值向0方向舍入；靠近0原则

• 取模运算 在计算商值时 商值向负无穷方向舍入；尽可能让商值小的原则(不超多商值的最大值)

## 3、总计算模/余数：a mod b = a – b[a/b]   ([a/b]表示整数商)

def solution(s):
print('INPUT:' + s)
i = (s+s).find(s,1, -1)
sub = s[:i]
print('Substring:', sub)

solution('abccbaabccba')
>> INPUT:abccbaabccba
>> Substring: abccba

solution('xyztxyztxyzt')
>> INPUT:xyztxyztxyzt
>> Substring: xyzt


def solution(s):
print('INPUT:' + s)
i = (s+s).find(s,1, -1)
sub = s[:i]
print("i:", i)
print('Substring_1:', sub)
s2 = s
s2 = s2[:-1]
sub2 = s2[0:len(set(s2))]
print('Substring_2:' +  sub2)

solution('wewewe')
>> INPUT:wewewe
>> i: 2
>> Substring_1: we
>> Substring_2:we

solution('weweweT')
>> INPUT:weweweT
>> i: -1
>> Substring_1: wewewe
>> Substring_2:we


find()

find() 方法从字符串中找出某个子字符串第一个匹配项的索引位置，该方法与index()方法一样，只不过如果子字符串不在字符串中不会报异常，而是返回-1。

S.find(sub[,start=0[,end=len(S)]])

• sub — 指定检索的子字符串

• S — 父字符串

• start — 可选参数，开始索引，默认为0。（可单独指定）

• end — 可选参数，结束索引，默认为字符串的长度。（不能单独指定）

quote = 'Let it be, let it be, let it be'
result = quote.find('let it')
print("Substring 'let it':", result)

Substring 'let it': 11


if len(set(s)) == 1:


def solution(s):
print('-------')
print('INPUT:' + s)
i = (s+s).find(s, 1, -1)
print (i)

if (len(s) % 2 != 0):
print('ODD')
if(len(set(s)) == 1):
print("CASE: ODD SINGLE CHARACTER")
print('pattern:' +  (s[0]))
print('Divisions:' + str(len(s)))
return
else:
s = s[:-1]
if len(set(s)) == 1:
print('pattern:' +  (s[0]))
print("CASE: ODD SINGLE CHARACTER EXTRA CHARACTER")
print('Divisions:' + str(len(s)))
return
elif i == -1:
sub = s[0:len(set(s))]
print('pattern:' +  sub)
print('Divisions:' + str(s.count(sub)))
print("CASE: MULTI CHARACTER EXTRA CHARACTER")
return
else:
sub = s[:i]
print('pattern:' +  sub)
print('Divisions:' + str(s.count(sub)))
print("CASE: ODD MULTI CHARACTER")
return
else:
print('EVEN')
if len(set(s)) == 1:
print('pattern:' +  (s[0]))
print('Divisions:' + str(len(s)))
print("CASE: EVEN SINGLE CHARACTER")
return
else:
sub = s[:i]
print('pattern:' +  sub)
print('Divisions:' + str(s.count(sub)))
print("CASE: EVEN MULTI CHARACTER")
return


solution('a')
solution('aa')
solution('abcabc')
solution('abcabcabc')
solution('aaT')
solution('ababT')


------
INPUT:a
-1
ODD
CASE: ODD SINGLE CHARACTER
pattern:a
Divisions:1
-------
INPUT:aa
1
EVEN
pattern:a
Divisions:2
CASE: EVEN SINGLE CHARACTER
-------
INPUT:abcabc
3
EVEN
pattern:abc
Divisions:2
CASE: EVEN MULTI CHARACTER
-------
INPUT:abcabcabc
3
ODD
pattern:abc
Divisions:2
CASE: ODD MULTI CHARACTER
-------
INPUT:aaT
-1
ODD
pattern:a
CASE: ODD SINGLE CHARACTER EXTRA CHARACTER
Divisions:2
-------
INPUT:ababT
-1
ODD
pattern:ab
Divisions:2
CASE: MULTI CHARACTER EXTRA CHARACTER


https://stackoverflow.com/questions/29481088/how-can-i-tell-if-a-string-repeats-itself-in-python

• 了解个人情况

• 一些关于计算机基础知识的题目

SRE 岗 5 轮面试大致考查如下方向：

## 总结一下

1、1 轮 foo.bar，2.5 轮电话面试，5 轮 onsite 面试，持续 4 个月，总体耗时 3–4 周。

2、 整个应聘的流程，至少接触了 4 位 recruiter，8 个面试官，2 个第三方服务者 ，算上人力的时间成本，加上 onsite 的机票酒店餐饮签证成本，最后再考虑下 onsite 的通过率，估计 Google 要招聘到一个合格的员工，成本至少是在十万人民币级别的。可见顶尖的人才是相当昂贵的，这还仅仅只是招聘成本。

3、就现在的 IT 技术招聘体制而言，大多数公司采用的无非就是在一定的时间和资源限制下，解决一些面试官心中有明确标准答案的 puzzles——但是这种选拔真得能很好的反应一个面试者在实际工作中的能力么？值得探讨···

4、你要知道，改善随着时间的推移，你的领域知识（语言和问题本身）和你的回答会变得更好。 如果你不能在一开始就不能很好地理解题目，也不能快速地想出一个很好的解决方案，不要气馁， 总有量变到质变的那一刻，你会感受到的！