Data structure is one of your favourite topics, isn’t it? Let’s design a new data structure! In this…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
n=int(input())
li=[]
for i in range(n):
s=input()
k=“”
if “Insert Back” in s:
for j in range(12,len(s)):
k+=s[j]
li.append(int(k))
elif “Insert Front” in s:
for j in range(13,len(s)):
k+=s[j]
li.insert(0,int(k))
elif “Erase Front” in s:
li.pop(0)
elif "Erase Back" in s:
li.pop()
elif s=="Get Front":
print(li[0])
elif "Get Back" in s:
print(li[len(li)-1])
elif "Get Max" in s:
print(max(li))
elif "Get Min" in s:
print(min(li))
You should avoid brute force methods here. Just avoid using loops.
in case of Python, you can try using insert method when C++ users might use dequeue.
Actually, I think this problem can be solved even without using any advanced data structures like list or dequeue.