Skip to content

Instantly share code, notes, and snippets.

@agumonkey
Created May 9, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agumonkey/8a81c0fd3f13bd5913deced9860ed75a to your computer and use it in GitHub Desktop.
Save agumonkey/8a81c0fd3f13bd5913deced9860ed75a to your computer and use it in GitHub Desktop.
## based on airbnb proto interview
def rev(s):
return s[::-1]
# a .. b
# (a,b) .. (b,a)
def mir(a,b):
i = a
j = b
while i <= b and j >= a:
yield (i,j)
i += 1
j -= 1
# a .. b
# (a,b) .. (b,a)
def mig(a,b):
i = a
j = b
while i < j:
yield (i,j)
i += 1
j -= 1
yield (i,j)
def rev_(s):
if s:
l = len(s)
o = bytearray(l)
for (i,j) in mig(0,l-1):
o[j] = ord(s[i])
o[i] = ord(s[j])
return o.decode()
else:
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment