Skip to content

Instantly share code, notes, and snippets.

@lucasdemarchi
Created July 13, 2018 18:57
Show Gist options
  • Save lucasdemarchi/7eeae4ea2722301c281dd9f47cbc2499 to your computer and use it in GitHub Desktop.
Save lucasdemarchi/7eeae4ea2722301c281dd9f47cbc2499 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import sys
s = list(sys.argv[1])
k = int(sys.argv[2])
r = 0
o = [''] * len(s)
chars = list("abcdefghijklmnopqrstuvwxyz")
# constant, up to 26
for c in chars:
# O(n)
pos = 0
while pos < len(s):
if s[pos] == c:
o[pos] = c
r = r + 1
if r == k:
break
pos = pos + 1
if r == k:
break
# O(n)
for x in o:
if x != '':
print(x, end='')
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment