Skip to content

Commit 91c78c0

Browse files
committed
HackerEarth: Data Structures Problems
1 parent 3d7d114 commit 91c78c0

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Albus Dumbledore announced that the school will host the legendary event known as Wizard Tournament where
2+
# four magical schools are going to compete against each other in a very deadly competition by facing some
3+
# dangerous challenges. Since the team selection is very critical in this deadly competition. Albus
4+
# Dumbledore asked Little Monk to help him in the team selection process. There is a long queue of students
5+
# from all the four magical schools. Each student of a school have a different roll number. Whenever a
6+
# new student will come, he will search for his schoolmate from the end of the queue. As soon as he will
7+
# find any of the schoolmate in the queue, he will stand behind him, otherwise he will stand at the end of
8+
# the queue. At any moment Little Monk will ask the student, who is standing in front of the queue, to
9+
# come and put his name in the Goblet of Fire and remove him from the queue. There are Q operations of
10+
# one of the following types:
11+
#
12+
# E x y: A new student of school x (1≤x≤4) whose roll number is (1≤y≤50000) will stand in queue according
13+
# to the method mentioned above.
14+
#
15+
# D: Little Monk will ask the student, who is standing in front of the queue, to come and put his name in
16+
# the Goblet of Fire and remove him from the queue
17+
#
18+
# Now Albus Dumbledore asked Little Monk to tell him the order in which student put their name. Little Monk
19+
# is too lazy to that so he asked you to write a program to print required order.
20+
#
21+
# Note: Number of dequeue operations will never be greater than enqueue operations at any point of time.
22+
#
23+
# Input Format:
24+
# First line contains an integer Q (1≤Q≤100000), denoting the number of operations. Next Q lines will contains
25+
# one of the 2 types of operations.
26+
#
27+
# Output Format:
28+
# For each 2nd type of operation, print two space separated integers, the front student's school and roll number.
29+
#
30+
# SAMPLE INPUT
31+
# 5
32+
# E 1 1
33+
# E 2 1
34+
# E 1 2
35+
# D
36+
# D
37+
#
38+
# SAMPLE OUTPUT
39+
# 1 1
40+
# 1 2
41+
42+
def enqueue(myList, element):
43+
try:
44+
index = [x for x, y in enumerate(myList) if x == element[0]]
45+
myList.insert(int(''.join([str(x) for x in index])), element)
46+
except ValueError:
47+
myList.insert(0, element)
48+
49+
def dequeue(myList):
50+
if len(myList) > 0:
51+
return myList.pop()
52+
53+
myList = []
54+
55+
for _ in range(int(input())):
56+
userInput = input().split()
57+
if userInput[0] == 'E':
58+
enqueue(myList, [int(userInput[1]), int(userInput[2])])
59+
else:
60+
deleted = dequeue(myList)
61+
print(' '.join([str(element) for element in deleted]))

0 commit comments

Comments
 (0)