Problem:


Doubly Linked List

Your task is to implement a double linked list.

Write a program which performs the following operations:

insert x: insert an element with key x into the front of the list.

delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.

deleteFirst: delete the first element from the list. 

deleteLast: delete the last element from the list. 

Input

The input is given in the following format:

n

command1 

command2 

...

commandn 

In the first line, the number of operations n is given. In the following n lines, the above mentioned operations are given in the following format:

insert x

delete x

deleteFirst 

deleteLast 

Output

Print all the element (key) in the list after the given operations. Two consequtive keys should be separated by a single space.

Constraints

The number of operations ≤ 2,000,000

The number of delete operations ≤ 20

0 ≤ value of a key ≤ 109

The number of elements in the list does not exceed 106

For a delete, deleteFirst or deleteLast operation, there is at least one element in the list.

Sample Input 1

7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5

Sample Output 1

6 1 2

Sample Input 2

9
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5
deleteFirst
deleteLast

Sample Output 2

1

Template in C
-->


Sample input:
7
insert 5
insert 2
insert 3
insert 1
delete 3
insert 6
delete 5


Sample output:
6 1 2

Submission status: Wrong Answer

Solution code:
# f = open('input.txt')

n = int(input())
# n = int(f.readline())
doubly_linked_list = []

for i in range(n):
    cmd = input()
    # cmd = f.readline().strip()
    print(cmd)
    if cmd == 'deleteFirst':
        doubly_linked_list.pop(0)
    elif cmd == 'deleteLast':
        doubly_linked_list.pop(-1)
    else:
        cmd, x = cmd.split()
        if cmd == 'insert':
            doubly_linked_list.insert(0, x)
        elif cmd == 'delete':
            doubly_linked_list.remove(x)
    print(doubly_linked_list)

print(' '.join(doubly_linked_list))

Submission status: Wrong Answer

Solution code:
n = int(input())

l = []
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        l.append(command[1])
    elif command[0] == "delete":
        try:
            ind = l.index(command[1])
            l.pop(ind)
        except ValueError:
            pass
    elif command[0] == "deleteFirst":
        l.pop(0)
    elif command[0] == "deleteLast":
        l.pop(-1)
        
print (" ".join(l[::-1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
    
class Node(object):
    """Node class
    """

    def __init__(self, key=None, previous_node=None, next_node=None):
        """Constructor
        """
        self.key = key
        ''' key '''

        self.previous_node = previous_node
        ''' previous node '''

        self.next_node = next_node
        ''' next node '''

    def copy_from(self, node):
        self.key = node.key
        self.previous_node = node.previous_node
        self.next_node = node.next_node

    def print_on(self, is_performance=False):
        if is_performance:
            print self.key, 
        else:
            print self.previous_node, str(self.key) + " at " + str(self), self.next_node


class DoublyLinkedList(object):
    """Doubly Linked List Class
    """

    def __init__(self, sentinel_key='SENTINEL'):
        """Constructor(make sentinel node)
        """
        self.sentinel_node = Node(key=sentinel_key)
        self.sentinel_node.next_node = self.sentinel_node
        self.sentinel_node.previous_node = self.sentinel_node

    def insert_node(self, key):
        """insert node which has specified key at first position"""
        
        # set new node
        new_node = Node(key=key, previous_node=self.sentinel_node, next_node=self.sentinel_node.next_node) 
        # re-set first_node
        self.sentinel_node.next_node.previous_node = new_node
        # re-set sentinel node
        self.sentinel_node.next_node = new_node

            

    def delete(self, key=None):
        """ delete node which has a key 'key' """
        target_node = self.sentinel_node.next_node
        while target_node is not self.sentinel_node:
            if target_node.key == key:
                target_node.previous_node.next_node = target_node.next_node
                target_node.next_node.previous_node = target_node.previous_node
                break
            else:
                target_node = target_node.next_node
    
    def delete_first(self):
        """ delete first node """
        # delete first node
        self.sentinel_node.next_node = self.sentinel_node.next_node.next_node
        self.sentinel_node.next_node.previous_node = self.sentinel_node

    def delete_last(self):
        """delete last node """
        self.sentinel_node.previous_node = self.sentinel_node.previous_node.previous_node
        self.sentinel_node.previous_node.next_node = self.sentinel_node

    def print_on(self, is_performance=False):
        target_node = self.sentinel_node
        if not is_performance:
            target_node.print_on(is_performance)
        while target_node.next_node is not self.sentinel_node:
            target_node = target_node.next_node
            target_node.print_on(is_performance)
            

def main():
    doubly_linked_list = DoublyLinkedList()

    input_length = int(raw_input())
    counter = 0
    while counter < input_length:
        counter += 1
        input_line = raw_input().strip()
        print input_line
        if input_line == 'deleteFirst':
            doubly_linked_list.delete_first()
            continue
        elif input_line == 'deleteLast':
            doubly_linked_list.delete_last()
            continue

        input_command = input_line.split(' ')[0].strip()
        input_key = input_line.split(' ')[1].strip()
        if input_command == 'insert':
            doubly_linked_list.insert_node(input_key)
        elif input_command == 'delete':
            doubly_linked_list.delete(input_key)
        else:
            "baka"
    doubly_linked_list.print_on(is_performance=True)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
    
class Node(object):
    """Node class
    """

    def __init__(self, key=None, previous_node=None, next_node=None):
        """Constructor
        """
        self.key = key
        ''' key '''

        self.previous_node = previous_node
        ''' previous node '''

        self.next_node = next_node
        ''' next node '''

    def copy_from(self, node):
        self.key = node.key
        self.previous_node = node.previous_node
        self.next_node = node.next_node

    def print_on(self, is_performance=False):
        if is_performance:
            print self.key, 
        else:
            print self.previous_node, str(self.key) + " at " + str(self), self.next_node


class DoublyLinkedList(object):
    """Doubly Linked List Class
    """

    def __init__(self, sentinel_key='SENTINEL'):
        """Constructor(make sentinel node)
        """
        self.sentinel_node = Node(key=sentinel_key)
        self.sentinel_node.next_node = self.sentinel_node
        self.sentinel_node.previous_node = self.sentinel_node

    def insert_node(self, key):
        """insert node which has specified key at first position"""
        
        # set new node
        new_node = Node(key=key, previous_node=self.sentinel_node, next_node=self.sentinel_node.next_node) 
        # re-set first_node
        self.sentinel_node.next_node.previous_node = new_node
        # re-set sentinel node
        self.sentinel_node.next_node = new_node

            

    def delete(self, key=None):
        """ delete node which has a key 'key' """
        target_node = self.sentinel_node.next_node
        while target_node is not self.sentinel_node:
            if target_node.key == key:
                target_node.previous_node.next_node = target_node.next_node
                target_node.next_node.previous_node = target_node.previous_node
                break
            else:
                target_node = target_node.next_node
    
    def delete_first(self):
        """ delete first node """
        # delete first node
        self.sentinel_node.next_node = self.sentinel_node.next_node.next_node
        self.sentinel_node.next_node.previous_node = self.sentinel_node

    def delete_last(self):
        """delete last node """
        self.sentinel_node.previous_node = self.sentinel_node.previous_node.previous_node
        self.sentinel_node.previous_node.next_node = self.sentinel_node

    def print_on(self, is_performance=False):
        target_node = self.sentinel_node
        if not is_performance:
            target_node.print_on(is_performance)
        while target_node.next_node is not self.sentinel_node:
            target_node = target_node.next_node
            target_node.print_on(is_performance)
            

def main():
    doubly_linked_list = DoublyLinkedList()

    input_length = int(raw_input())
    counter = 0
    while counter < input_length:
        counter += 1
        input_line = raw_input().strip()
        # print input_line
        if input_line == 'deleteFirst':
            doubly_linked_list.delete_first()
            continue
        elif input_line == 'deleteLast':
            doubly_linked_list.delete_last()
            continue

        input_command = input_line.split(' ')[0].strip()
        input_key = input_line.split(' ')[1].strip()
        if input_command == 'insert':
            doubly_linked_list.insert_node(input_key)
        elif input_command == 'delete':
            doubly_linked_list.delete(input_key)
        else:
            "baka"
    # doubly_linked_list.print_on(is_performance=True)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
    
class Node(object):
    """Node class
    """

    def __init__(self, key=None, previous_node=None, next_node=None):
        """Constructor
        """
        self.key = key
        ''' key '''

        self.previous_node = previous_node
        ''' previous node '''

        self.next_node = next_node
        ''' next node '''

    def copy_from(self, node):
        self.key = node.key
        self.previous_node = node.previous_node
        self.next_node = node.next_node

    def print_on(self, is_performance=False):
        if is_performance:
            pass
            print self.key, 
        else:
            print self.previous_node, str(self.key) + " at " + str(self), self.next_node


class DoublyLinkedList(object):
    """Doubly Linked List Class
    """

    def __init__(self, sentinel_key='SENTINEL'):
        """Constructor(make sentinel node)
        """
        self.sentinel_node = Node(key=sentinel_key)
        self.sentinel_node.next_node = self.sentinel_node
        self.sentinel_node.previous_node = self.sentinel_node

    def insert_node(self, key):
        """insert node which has specified key at first position"""
        
        # set new node
        new_node = Node(key=key, previous_node=self.sentinel_node, next_node=self.sentinel_node.next_node) 
        # re-set first_node
        self.sentinel_node.next_node.previous_node = new_node
        # re-set sentinel node
        self.sentinel_node.next_node = new_node

            
    def delete(self, key=None):
        """ delete node which has a key 'key' """
        target_node = self.sentinel_node.next_node
        while target_node is not self.sentinel_node:
            if target_node.key == key:
                target_node.previous_node.next_node = target_node.next_node
                target_node.next_node.previous_node = target_node.previous_node
                break
            else:
                target_node = target_node.next_node
    
    def delete_first(self):
        """ delete first node """
        # delete first node
        self.sentinel_node.next_node = self.sentinel_node.next_node.next_node
        self.sentinel_node.next_node.previous_node = self.sentinel_node

    def delete_last(self):
        """delete last node """
        self.sentinel_node.previous_node = self.sentinel_node.previous_node.previous_node
        self.sentinel_node.previous_node.next_node = self.sentinel_node

    def print_on(self, is_performance=False):
        target_node = self.sentinel_node
        if not is_performance:
            target_node.print_on(is_performance)
        while target_node.next_node is not self.sentinel_node:
            target_node = target_node.next_node
            target_node.print_on(is_performance)
            

def main():
    doubly_linked_list = DoublyLinkedList()

    input_length = int(raw_input())
    counter = 0
    while counter < input_length:
        counter += 1
        input_line = raw_input().strip()
        # print input_line
        if input_line == 'deleteFirst':
            doubly_linked_list.delete_first()
            continue
        elif input_line == 'deleteLast':
            doubly_linked_list.delete_last()
            continue

        input_command = input_line.split(' ')[0].strip()
        input_key = input_line.split(' ')[1].strip()
        if input_command == 'insert':
            doubly_linked_list.insert_node(input_key)
        elif input_command == 'delete':
            pass
            # doubly_linked_list.delete(input_key)
    doubly_linked_list.print_on(is_performance=True)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
class Node:
    elm = None
    nxt = None
    prev = None

    def __init__(self, elm=None, prev=None, nxt=None):
        self.elm = elm
        self.prev = prev
        self.nxt = nxt


class MyDLList:
    size = 0
    head = tail = None
    dic = dict()

    def insert(self, elm):
        if self.is_empty():
            self.dic[elm] = [Node(elm)]
            self.head = self.tail = self.dic[elm][0]
        elif self.dic.get(elm):
            self.dic[elm].append(Node(elm))
            self.dic[elm][-1].nxt = self.head
            self.head.prev = self.dic[elm][-1]
            self.head = self.dic[elm][-1]
        else:
            self.dic[elm] = [Node(elm)]
            self.dic[elm][0].nxt = self.head
            self.head.prev = self.dic[elm][0]
            self.head = self.dic[elm][0]
        self.size += 1

    def list_search(self, elm):
        # cur = self.head
        # if cur != self.tail:
        #     i = 1
        #     while i < self.size and cur.elm != x:
        #         cur = cur.nxt
        #         i += 1
        # if cur.elm != x:
        #     cur = None
        return self.dic.get(elm)

    def delete(self, elm):
        cur = self.list_search(elm)
        if cur:
            if cur[-1] == self.head:
                self.delete_first()
            elif cur[0] == self.tail:
                self.delete_last()
            else:
                deleted = cur.pop(-1)
                deleted.prev.nxt = deleted.nxt
                deleted.nxt.prev = deleted.prev
                self.size -= 1
                return deleted.elm

    def delete_first(self):
        # ????§???§?????°????????¨??????????????????????´???????????????¨???????????????
        cur = self.head
        if self.size != 1:
            self.dic[self.head.elm].pop(-1)
            self.head.nxt.prev = None
            self.head = self.head.nxt
        else:
            self.dic.clear()
            self.head = self.tail = None

        self.size -= 1
        return cur.elm

    def delete_last(self):
        # ????§???§?????°????????¨??????????????????????´???????????????¨???????????????
        cur = self.tail
        if self.size != 1:
            self.dic[self.tail.elm].pop(0)
            self.tail.prev.nxt = None
            self.tail = self.tail.prev
        else:
            self.dic.clear()
            self.tail = self.head = None
        self.size -= 1
        return cur.elm

    def is_empty(self):
        return self.size == 0

    def __str__(self):
        cur = self.head
        output = ""
        i = 1
        while i < self.size:
            output += str(cur.elm) + " "
            cur = cur.nxt
            i += 1
        output += str(cur.elm)
        return output


n = int(input())

dl = MyDLList()

for i in range(n):
    x = list(map(str, input().split()))
    if x[0] == "insert":
        dl.insert(int(x[1]))
    elif x[0] == "delete":
        dl.delete(int(x[1]))
    elif x[0] == "deleteFirst":
        dl.delete_first()
    elif x[0] == "deleteLast":
        dl.delete_last()

print(dl)

Submission status: Wrong Answer

Solution code:
class Node:
    elm = None
    nxt = None
    prev = None

    def __init__(self, elm=None, prev=None, nxt=None):
        self.elm = elm
        self.prev = prev
        self.nxt = nxt


class MyDLList:
    size = 0
    head = tail = None
    dic = dict()

    def insert(self, elm):
        if self.is_empty():
            self.dic[elm] = [Node(elm)]
            self.head = self.tail = self.dic[elm][0]
        elif self.dic.get(elm):
            self.dic[elm].append(Node(elm))
            self.dic[elm][-1].nxt = self.head
            self.head.prev = self.dic[elm][-1]
            self.head = self.dic[elm][-1]
        else:
            self.dic[elm] = [Node(elm)]
            self.dic[elm][0].nxt = self.head
            self.head.prev = self.dic[elm][0]
            self.head = self.dic[elm][0]
        self.size += 1

    # def list_search(self, elm):
    #     # cur = self.head
    #     # if cur != self.tail:
    #     #     i = 1
    #     #     while i < self.size and cur.elm != x:
    #     #         cur = cur.nxt
    #     #         i += 1
    #     # if cur.elm != x:
    #     #     cur = None
    #     return self.dic.get(elm)

    def delete(self, elm):
        cur = self.dic.get(elm)
        if cur:
            if cur[-1] == self.head:
                self.delete_first()
            elif cur[-1] == self.tail:
                self.delete_last()
            else:
                deleted = cur.pop(-1)
                deleted.prev.nxt = deleted.nxt
                deleted.nxt.prev = deleted.prev
                self.size -= 1
                return deleted.elm

    def delete_first(self):
        # ????§???§?????°????????¨??????????????????????´???????????????¨???????????????
        cur = self.head
        if self.size != 1:
            self.dic[self.head.elm].pop(-1)
            self.head.nxt.prev = None
            self.head = self.head.nxt
        else:
            self.dic.clear()
            self.head = self.tail = None

        self.size -= 1
        return cur.elm

    def delete_last(self):
        # ????§???§?????°????????¨??????????????????????´???????????????¨???????????????
        cur = self.tail
        if self.size != 1:
            self.dic[self.tail.elm].pop(-1)
            self.tail.prev.nxt = None
            self.tail = self.tail.prev
        else:
            self.dic.clear()
            self.tail = self.head = None
        self.size -= 1
        return cur.elm

    def is_empty(self):
        return self.size == 0

    def __str__(self):
        cur = self.head
        output = ""
        i = 1
        while i < self.size:
            output += str(cur.elm) + " "
            cur = cur.nxt
            i += 1
        output += str(cur.elm)
        return output


n = int(input())

dl = MyDLList()

for i in range(n):
    x = list(map(str, input().split()))
    if x[0] == "insert":
        dl.insert(int(x[1]))
    elif x[0] == "delete":
        dl.delete(int(x[1]))
    elif x[0] == "deleteFirst":
        dl.delete_first()
    elif x[0] == "deleteLast":
        dl.delete_last()

print(dl)

Submission status: Wrong Answer

Solution code:
class Node:
	elm = None
	next = None
	prev = None

class MyQueue:
	head = tail = None
	def enq(self, x):
		n = Node()
		n.elm = x
		if self.head == None:
			self.head = self.tail = n
		else:
			self.tail.next = n
			n.prev = self.tail
			self.tail = n

	def deq(self):
		if self.head == None:
			return None
		x = self.head.elm
		self.head = self.head.next
		if self.head: 
			self.head.prev = None
		else:
			self.tail = None
		return x

	def pop(self):
		if self.tail == None:
			return None
		x = self.tail.elm
		self.tail = self.tail.prev
		if self.tail: 
			self.tail.next = None
		else:
			self.head = None
		return x

class MyList:
	head = tail = None
	lookup = {}

	def insert(self, x):
		n = Node()
		n.elm = x
		if self.head == None:
			self.head = self.tail = n
		else:
			n.next = self.head
			self.head.prev = n
			self.head = n
		if not x in self.lookup:
			self.lookup[x] = MyQueue()
		self.lookup[x].enq(n)

	def delete(self, x):
		n = self.lookup[x].deq()
		self.__delete_node(n)

	def deleteFirst(self):
		self.lookup[self.head.elm].deq()
		self.__delete_node(self.head)

	def deleteLast(self):
		self.lookup[self.tail.elm].pop()
		self.__delete_node(self.tail)

	def __delete_node(self, n):
		if n == None: 
			return
		if n == self.head:
			self.head = n.next
		if n == self.tail:
			self.tail = n.prev
		if n.prev:
			n.prev.next = n.next
		if n.next:
			n.next.prev = n.prev

	def __traverse(self):
		n = self.head
		while n:
			yield n.elm
			n = n.next

	def __str__(self):
		return " ".join([str(s) for s in self.__traverse()])

myList = MyList()
n = int(raw_input())
for _ in xrange(n):
	line = raw_input()
	if line[0]=='i':
		myList.insert(int(line[7:]))
	elif line[6]=='F':
		myList.deleteFirst()
	elif line[6]=='L':
		myList.deleteLast()
	else:
		myList.delete(int(line[7:]))
print myList

Submission status: Wrong Answer

Solution code:
class MyDLList:
    head = tail = None
    size = 0

    def append_left(self, elm):
        if self.is_empty():
            self.head = self.tail = [elm, None, None]
            # elm, prev, next
        else:
            cur = [elm, None, self.head]
            self.head[1] = cur
            self.head = cur
        self.size += 1

    def is_empty(self):
        return self.size == 0

    def list_search(self, elm):
        cur = self.head
        i = 1
        while i < self.size and cur[0] != elm:
            cur = cur[2]
            i += 1
        return cur

    def delete(self, elm):
        if self.is_empty():
            deleted = None
        else:
            cur = self.list_search(elm)
            if cur == self.head:
                deleted = self.delete_first()
            elif cur == self.tail:
                deleted = self.delete_last()
            else:
                deleted = cur[0]
                cur[1][2] = cur[2]
                cur[2][1] = cur[1]
                self.size -= 1
        return deleted

    def delete_first(self):
        cur = self.head
        self.head[2][1] = None
        self.head = self.head[2]
        self.size -= 1
        return cur[0]

    def delete_last(self):
        cur = self.tail
        self.tail[1][2] = None
        self.tail = self.tail[1]
        self.size -= 1
        return cur[0]

    def __str__(self):
        cur = self.head
        result = ""
        for _ in range(1, self.size):
            result += cur[0] + " "
            cur = cur[2]

        result += cur[0]
        return result

n = int(input())

dl = MyDLList()


for i in range(n):
    x = list(map(str, input().split()))
    if x[0] == "insert":
        dl.append_left(x[1])
    elif x[0] == "delete":
        dl.delete(x[1])
    elif x[0] == "deleteFirst":
        dl.delete_first()
    elif x[0] == "deleteLast":
        dl.delete_last()

print(dl)

Submission status: Wrong Answer

Solution code:
class MyDLList:
    head = tail = None
    size = 0

    def append_left(self, elm):
        if self.is_empty():
            self.head = self.tail = [elm, None, None]
            # elm, prev, next
        else:
            cur = [elm, None, self.head]
            self.head[1] = cur
            self.head = cur
        self.size += 1

    def is_empty(self):
        return self.size == 0

    def list_search(self, elm):
        cur = self.head
        i = 1
        while i < self.size and cur[0] != elm:
            cur = cur[2]
            i += 1
        if cur != elm:
            cur = None
        return cur

    def delete(self, elm):
        cur = self.list_search(elm)
        if cur:
            if cur == self.head:
                deleted = self.delete_first()
            elif cur == self.tail:
                deleted = self.delete_last()
            else:
                deleted = cur[0]
                cur[1][2] = cur[2]
                cur[2][1] = cur[1]
                self.size -= 1
        else:
            deleted = None
        return deleted

    def delete_first(self):
        cur = self.head
        self.head[2][1] = None
        self.head = self.head[2]
        self.size -= 1
        return cur[0]

    def delete_last(self):
        cur = self.tail
        self.tail[1][2] = None
        self.tail = self.tail[1]
        self.size -= 1
        return cur[0]

    def __str__(self):
        cur = self.head
        result = ""
        while cur != self.tail:
            result += cur[0] + " "
            cur = cur[2]
        result += cur[0]
        return result

n = int(input())

dl = MyDLList()


for i in range(n):
    x = list(map(str, input().split()))
    if x[0] == "insert":
        dl.append_left(x[1])
    elif x[0] == "delete":
        dl.delete(x[1])
    elif x[0] == "deleteFirst":
        dl.delete_first()
    elif x[0] == "deleteLast":
        dl.delete_last()

print(dl)

Submission status: Wrong Answer

Solution code:
from collections import deque

if __name__ == '__main__':
    n = int(input())
    L = deque()
    for i in range(n):
        cmd = input().split()

        if cmd[0] == 'insert':
            L.appendleft(cmd[1])
        if cmd[0] == 'delete':
            L.remove(cmd[1])
        if cmd[0] == 'deleteFirst':
            L.popleft()
        if cmd[0] == 'Last':
            L.pop()
    print(*L)

Submission status: Wrong Answer

Solution code:

n = int(input())
output = []
#for i in range(n):
#    order,data =input().split() 
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Wrong Answer

Solution code:

n = int(input())
output = []
for i in range(n):
    order = map(str,input().split())
#    if order == "insert":
#        output.append(int(data))
#    elif order == "deleteFirst":
#        output.pop()
#    elif order == "deleteLast":
#        output.popleft()

#   elif order == "delete":
#        try:
#            output.remove(int(data))
#        except:
#            pass
#output.reverse()
print(" ".join(output))
#print(" ".join(map(str,output)))

Submission status: Wrong Answer

Solution code:
from collections import deque

N=int(input())
l=[]
q=deque(l)

for i in range(N):
    tmp = input().split()
    com = tmp[0]
    if com == 'deleteFirst':
        q.popleft()
    elif com == 'deleteLast':
        q.pop()
    else:
        val = int(tmp[1])
        if com == 'insert':
            q.appendleft(val)
        elif com == 'delete':
            q.reverse()
            q.remove(val)
            q.reverse()

ret = list(q)
print(' '.join(map(str,ret)))

Submission status: Wrong Answer

Solution code:
n = input()
l = []
for i in range(int(n)):
	command = input()
	if command[0] == 'i':
		l.insert(0, command[7:])
	else:
		if command[6] == " ":
			if  command[7:] in l:
				l.remove(command[7:])
		else:
			if command[7] == 'L':
				l.pop()
			else:
				l.pop(0)
for i in l[:-1]:
	print(i, end=' ')
print(l[-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
n = input()
d = deque()
for i in range(int(n)):
	command = input()
	if command[0] == 'i':
		d.appendleft(command[7:])
	else:
		if command[6] == " ":
			if  command[7:] in d:
				d.remove(command[7:])
		else:
			if command[6] == 'L':
				d.pop()
			else:
				d.popleft()
for _ in range(len(d)-1):
	print(d.pop(), end=" ")
print(d.pop())

Submission status: Wrong Answer

Solution code:
def insert_ele(x):
    lin.insert(0,x)
def delete_ele(x):
    lin.remove(x)
def deleteFirst():
    lin.pop(0)
def deleteLast():
    lin.pop()

cnt = input()
lin = []

for i in range(int(cnt)):
    com = input().split()
    if com[0] == "insert":
        insert_ele(int(com[1]))
    if com[0] == "delete":
        delete_ele(int(com[1]))
    if com[0] == "deleteFirst":
        deleteFirst()
    if com[0] == "deleteLast":
        deleteLast()

for i in range(len(lin)):
    print (lin[0], end = "")
print()

Submission status: Wrong Answer

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
n=int(input())
L=[]
for i in range(n):
    cmd=input().split()
    if(cmd[0]=="insert"):
        L.append(cmd[1])
    if(cmd[0]=="delete" and cmd[1] in L):
        L.remove(cmd[1])
    if(cmd[0]=="deleteFirst"):
        L.pop(0)
    if(cmd[0]=="deleteFirst"):
        L.pop()
s=""
for i in L:
    s+=i+" "
print(s[:-1])

Submission status: Wrong Answer

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
n=int(input())
L=[]
for i in range(n):
    cmd=input().split()
    if(cmd[0]=="insert"):
        L.append(cmd[1])
    if(cmd[0]=="delete" and cmd[1] in L):
        L.remove(cmd[1])
    if(cmd[0]=="deleteFirst"):
        L.pop(0)
    if(cmd[0]=="deleteLast"):
        L.pop()
s=""
for i in L:
    s+=i+" "
print(s[:-1])

Submission status: Wrong Answer

Solution code:
#ALDS1_3-C Elementary data structures - Doubly Linked List
n=int(input())
L=[]
for i in range(n):
    cmd=input().split()
    if(cmd[0]=="insert"):
        L=[cmd[1]]+L
    elif(cmd[0]=="delete" and cmd[1] in L):
        L.remove(cmd[1])
    elif(cmd[0]=="deleteFirst"):
        L.pop(0)
    else:
        L.pop()
s=""
for i in L:
    s+=i+" "
print(s[:-1])