given a stack stutter takes a stack as a parameter and replaces every value in the stack with two occurrences of that value for example suppose the stack stores these values bottom 3 7 1 14 9 top then the stack should store these values after the method terminates bottom 3 3 7 7 1 1 14 14 9 9 top note there are 2 solutions firststutter it uses a single stack as auxiliary storage secondstutter it uses a single queue as auxiliary storage put all values into queue from stack put values back into stack from queue now stack is reverse put all values into queue from stack put 2 times value into stack from queue put all values into queue from stack put values back into stack from queue now stack is reverse put all values into queue from stack put 2 times value into stack from queue
import collections


def first_stutter(stack):
    storage_stack = []
    for i in range(len(stack)):
        storage_stack.append(stack.pop())
    for i in range(len(storage_stack)):
        val = storage_stack.pop()
        stack.append(val)
        stack.append(val)

    return stack


def second_stutter(stack):
    q = collections.deque()
    
    for i in range(len(stack)):
        q.append(stack.pop())
    
    for i in range(len(q)):
        stack.append(q.pop())
    
    for i in range(len(stack)):
        q.append(stack.pop())
    
    for i in range(len(q)):
        val = q.pop()
        stack.append(val)
        stack.append(val)

    return stack