You are viewing a single comment's thread. Return to all comments →
def process_queue(queries: list[str]): def consume_entry_stack(x, y): for _ in range(len(x)): y.append(x.pop()) s1 = [] s2 = [] for query in queries: match query.split(): case '1', data: s1.append(data) case ['2']: if len(s2) == 0: consume_entry_stack(s1, s2) s2.pop() case ['3']: if len(s2) == 0: consume_entry_stack(s1, s2) print(s2[-1]) if __name__ == '__main__': n = input() queries = [] for _ in range(int(n)): queries.append(input()) process_queue(queries
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →