Skip to content

Commit 1055425

Browse files
Remember Previous Queries Solved
1 parent f7b1f63 commit 1055425

5 files changed

+51
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Remember Previous Queries?","group":"HackerRank - Mid Term Exam | Basic Data Structures | Batch 05","url":"https://www.hackerrank.com/contests/mid-term-exam-a-basic-data-structures-a-batch-05/challenges/remember-previous-queries","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"4\n0 10\n1 20\n1 30\n0 40\n","output":"L -> 10\nR -> 10\nL -> 10 20\nR -> 20 10\nL -> 10 20 30\nR -> 30 20 10\nL -> 40 10 20 30\nR -> 30 20 10 40\n","id":1722000354757},{"input":"9\n0 10\n2 1\n2 0\n1 20\n0 10\n2 2\n2 1\n2 2\n2 0\n","output":"L -> 10\nR -> 10\nL -> 10\nR -> 10\nL ->\nR ->\nL -> 20\nR -> 20\nL -> 10 20\nR -> 20 10\nL -> 10 20\nR -> 20 10\nL -> 10\nR -> 10\nL -> 10\nR -> 10\nL ->\nR ->\n","id":1722000354795},{"input":"11\n0 10\n2 5\n1 20\n1 30\n0 40\n2 0\n0 50\n2 2\n1 60\n2 3\n2 3\n","output":"L -> 10\nR -> 10\nL -> 10\nR -> 10\nL -> 10 20\nR -> 20 10\nL -> 10 20 30\nR -> 30 20 10\nL -> 40 10 20 30\nR -> 30 20 10 40\nL -> 10 20 30\nR -> 30 20 10\nL -> 50 10 20 30\nR -> 30 20 10 50\nL -> 50 10 30\nR -> 30 10 50\nL -> 50 10 30 60\nR -> 60 30 10 50\nL -> 50 10 30\nR -> 30 10 50\nL -> 50 10 30\nR -> 30 10 50\n","id":1722000354745},{"input":"10\n1 4\n2 1\n0 9\n0 10\n2 2\n1 5\n2 0\n2 1\n2 5\n2 2\n","output":"L -> 4\nR -> 4\nL -> 4\nR -> 4\nL -> 9 4\nR -> 4 9\nL -> 10 9 4\nR -> 4 9 10\nL -> 10 9\nR -> 9 10\nL -> 10 9 5\nR -> 5 9 10\nL -> 9 5\nR -> 5 9\nL -> 9\nR -> 9\nL -> 9\nR -> 9\nL -> 9\nR -> 9\n","id":1722000354792}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"RememberPreviousQueries"}},"batch":{"id":"6b9b29af-ae73-4df4-a4e3-ffda6385b01f","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\3. Basic Data Structures\\Remember_Previous_Queries.cpp"}

Remember_Previous_Queries.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
list<int> myList;
7+
int q;
8+
cin >> q;
9+
while (q--)
10+
{
11+
int x, v;
12+
cin >> x >> v;
13+
if (x == 0)
14+
myList.push_front(v);
15+
else if (x == 1)
16+
myList.push_back(v);
17+
else if (x == 2 && int(v) < int(myList.size()))
18+
myList.erase(next(myList.begin(), v));
19+
20+
cout << "L -> ";
21+
for (int val : myList)
22+
{
23+
cout << val << " ";
24+
}
25+
cout << endl;
26+
27+
list<int> listcpy = myList;
28+
listcpy.reverse();
29+
30+
cout << "R -> ";
31+
for (int reverseVal : listcpy)
32+
{
33+
cout << reverseVal << " ";
34+
}
35+
cout << endl;
36+
}
37+
38+
return 0;
39+
}

Remember_Previous_Queries.exe

74 KB
Binary file not shown.

input.txt

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
10
1+
4
22
0 10
33
1 20
4-
0 30
5-
1 40
6-
6 50
7-
0 60
8-
4 70
9-
4 80
10-
2 90
11-
1 100
4+
1 30
5+
0 40

output.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
L -> 10
2+
R -> 10
3+
L -> 10 20
4+
R -> 20 10
5+
L -> 20 10 30
6+
R -> 30 10 20
7+
L -> 40 30 10 20
8+
R -> 20 10 30 40

0 commit comments

Comments
 (0)