Skip to content

Commit 0336457

Browse files
Browser History Problem Solved
1 parent 3c3342f commit 0336457

6 files changed

+81
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Browser History","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/browser-history-1","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"facebook google phitron youtube twitter end\n12\nvisit phitron\nprev\nprev\nprev\nprev\nnext\nvisit twitter\nnext\nnext\nprev\nvisit django\nprev\n","output":"phitron\ngoogle\nfacebook\nNot Available\nNot Available\ngoogle\ntwitter\nNot Available\nNot Available\nyoutube\nNot Available\nphitron\n","id":1721967756868},{"input":"a b c d e f g h i j k l m n o p q r s t u v w x y z end\n7\nvisit s\nnext\nvisit zz\nnext\nvisit z\nnext\nprev\n","output":"s\nt\nNot Available\nu\nz\nNot Available\ny\n","id":1721967756859}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BrowserHistory"}},"batch":{"id":"304c56cf-7cec-453c-863a-3dea8e7a70d5","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\3. Basic Data Structures\\Browser_History.cpp"}

Browser_History.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
list<string> myList;
7+
while (true)
8+
{
9+
string v;
10+
cin >> v;
11+
if (v == "end")
12+
break;
13+
myList.push_back(v);
14+
}
15+
16+
int q;
17+
cin >> q;
18+
cin.ignore();
19+
auto cLocation = myList.begin();
20+
while (q--)
21+
{
22+
string visit;
23+
getline(cin, visit);
24+
if (visit == "prev")
25+
{
26+
if (cLocation == myList.begin())
27+
cout << "Not Available" << endl;
28+
else
29+
{
30+
--cLocation;
31+
cout << *cLocation << endl;
32+
}
33+
}
34+
else if (visit == "next")
35+
{
36+
if (next(cLocation) == myList.end())
37+
cout << "Not Available" << endl;
38+
else
39+
{
40+
++cLocation;
41+
cout << *cLocation << endl;
42+
}
43+
}
44+
else
45+
{
46+
string value = visit.substr(6);
47+
auto it = find(myList.begin(), myList.end(), value);
48+
if (it == myList.end())
49+
cout << "Not Available" << endl;
50+
else
51+
{
52+
cLocation = it;
53+
cout << *it << endl;
54+
}
55+
}
56+
}
57+
58+
return 0;
59+
}

Browser_History.exe

86.7 KB
Binary file not shown.

input.txt

+14-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
1 2 2 1 -1
1+
facebook google phitron youtube twitter end
2+
12
3+
visit phitron
4+
prev
5+
prev
6+
prev
7+
prev
8+
next
9+
visit twitter
10+
next
11+
next
12+
prev
13+
visit django
14+
prev

output.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
YES

tempCodeRunnerFile.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
ong int i = 0; i < n; i++)
2-
// {
3-
// cout << pre[i] << endl;
4-
// }
1+
ocation == myList.end())
2+
// cout << "Not Available" << endl;
3+
// else
4+
// {
5+
// cLocation++;
6+
// cout << *cLocation << endl;
7+
// }

0 commit comments

Comments
 (0)