Skip to content

Commit b71c225

Browse files
Same or Not Using STL Stack & Queue Solved
1 parent f9b7d60 commit b71c225

4 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Same or Not","group":"HackerRank - Assignment 03 | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/assignment-03-a-basic-data-structure-a-batch-05/challenges/same-or-not-ii","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"5 5\n10 20 30 40 50\n50 40 30 20 10\n","output":"YES\n","id":1723006246919},{"input":"4 4\n10 20 30 40\n10 20 30 40\n","output":"NO\n","id":1723006246947},{"id":1723006246877,"input":"5 4\n1 2 3 4 5\n5 4 3 2\n","output":"NO\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"SameOrNot"}},"batch":{"id":"b19b32af-f448-46c3-a86b-313fadaf2d53","size":1},"srcPath":"c:\\xampp\\htdocs\\Phitron\\Basic_Data_Structures\\Same_or_Not.cpp"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Same or Not II","group":"HackerRank - Assignment 03 | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/assignment-03-a-basic-data-structure-a-batch-05/challenges/same-or-not-4","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"5 5\n10 20 30 40 50\n50 40 30 20 10\n","output":"YES\n","id":1723011278114},{"input":"4 4\n10 20 30 40\n10 20 30 40\n","output":"NO\n","id":1723011278154},{"input":"5 4\n1 2 3 4 5\n5 4 3 2\n","output":"NO\n","id":1723011278140}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"SameOrNotII"}},"batch":{"id":"9f4f7301-443d-4fb2-bf72-b064f7afd343","size":1},"srcPath":"c:\\xampp\\htdocs\\Phitron\\Basic_Data_Structures\\Same_or_Not_II.cpp"}

Same_or_Not.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n, m;
7+
cin >> n >> m;
8+
9+
if (n != m)
10+
{
11+
cout << "NO" << endl;
12+
return 0;
13+
}
14+
15+
stack<int> st;
16+
queue<int> q;
17+
18+
for (int i = 0; i < n; i++)
19+
{
20+
int x;
21+
cin >> x;
22+
st.push(x);
23+
}
24+
25+
for (int i = 0; i < m; i++)
26+
{
27+
int x;
28+
cin >> x;
29+
q.push(x);
30+
}
31+
32+
bool flag = true;
33+
34+
while (!st.empty() && !q.empty())
35+
{
36+
if (st.top() != q.front())
37+
{
38+
flag = false;
39+
break;
40+
}
41+
st.pop();
42+
q.pop();
43+
}
44+
45+
if (flag)
46+
cout << "YES" << endl;
47+
else
48+
cout << "NO" << endl;
49+
50+
return 0;
51+
}

Same_or_Not_II.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)