Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
popleft solution in Clear category for Letter Queue by pokosasa
from collections import deque
def letter_queue(commands):
res=deque()
for command in commands:
if command=="POP":
if res:
res.popleft()
else:
arg=command.split()[1]
res.append(arg)
res="".join(res)
return res
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert letter_queue(["PUSH A", "POP", "POP", "PUSH Z", "PUSH D", "PUSH O", "POP", "PUSH T"]) == "DOT", "dot example"
assert letter_queue(["POP", "POP"]) == "", "Pop, Pop, empty"
assert letter_queue(["PUSH H", "PUSH I"]) == "HI", "Hi!"
assert letter_queue([]) == "", "Nothing"
May 6, 2020
Comments: