-
-
Save lucasdemarchi/7eeae4ea2722301c281dd9f47cbc2499 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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