Skip to content

Instantly share code, notes, and snippets.

@kanglicheng
Last active October 9, 2017 19:54
Show Gist options
  • Save kanglicheng/943a5fd6a2c500db23c4ef08e9f4b687 to your computer and use it in GitHub Desktop.
Save kanglicheng/943a5fd6a2c500db23c4ef08e9f4b687 to your computer and use it in GitHub Desktop.
#my coderbyte solns, from mock skype interviews
def RunLength(string):
count =1
ans = ""
for i in range(len(string)-1):
if string[i] == string[i+1]:
count +=1
elif string[i] != string[i+1]:
ans += str(count)
ans += string[i]
count =1
return ans + str(count) + string[i+1]
# 10/9/17 10:00 AM PST, return number of brackets to remove for the expression to be balanced
def RemoveBrackets(str):
stack =[]
count = 0
for c in str:
if c == "(":
stack.append("(")
elif c == ")" and len(stack)==0:
count += 1
elif c == ")":
stack.pop()
return count+len(stack)
#10/9/17 11:00 AM PST, given a sentence, return the word with the most repeated letters
def LetterCountI(string):
mostReps, d, maxCount, start = "", {}, 1, 0
for i, c in enumerate(string):
if c == " ":
if max(d.values()) > maxCount:
maxCount = max(d.values())
mostReps = string[start:i]
start = i+1
d= {}
else:
d[c]=1 if c not in d else d[c]+1
if max(d.values()) > maxCount:
mostReps = string[start:i+1]
return -1 if mostReps == "" else mostReps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment