mailming
BAN USER- 1of 1 vote
AnswersGot FB interview questions is not difficult, basically, he is asking to count number of identical chars in a given string with with some special case handling, and return the number with highest count, question is pretty long leaving you to dig an algorithm.
Etc, given string "coffee tuffee", should return 4.
I was having my usual interview brain freeze, and start doing initializing with int, how silly
well after interview when I cool down, it doesn't take long to figure out as code below, little over weighted algorithm but the most concise I can wrote, someone please give more efficient code.
- mailming in United Statesdef parseword(a_word): a_word=a_word.lower() count=list(map(a_word.count, a_word)) return (max(count))
| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Python
#cannot find any clean way to use split
import re
a_input=(1, (2, 3), (4, (5, 6), 7))
sep=re.compile('[(,) ]+')
b_string=sep.split(str(a_input))
#always got empty string after splitting, anyone can brighten this up?
while '' in b_string: b_string.remove('')
print (tuple(map(int,b_string)))
#use recursive to flat all the way to element, and then append back to single tuple element, similar for list implementation too.
a_tuple = (1, (2, 3), (4, (5, 6), 7))
def flat(a):
if isinstance(a,int):
return (a,)
else:
fulltuple=();
for i in range(len(a)):
fulltuple+=flat(a[i])
return fulltuple
print (flat(a_tuple))
- mailming October 20, 2015