Skip to content

Commit f51a3e5

Browse files
committedJul 8, 2024
Checking if the array is sorted or not using c++
1 parent 9d10440 commit f51a3e5

9 files changed

+50
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Insert it","group":"HackerRank - Assignment 01 | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/assignment-01-a-basic-data-structure-a-batch-05/challenges/insert-the-vector","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"5\n2 3 4 5 6\n3\n10 20 30\n3\n","output":"2 3 4 10 20 30 5 6\n","id":1720457307283},{"input":"5\n2 3 4 5 6\n3\n10 20 30\n0\n","output":"10 20 30 2 3 4 5 6\n","id":1720457307201},{"input":"4\n3 4 5 6\n3\n10 20 30\n4\n","output":"3 4 5 6 10 20 30\n","id":1720457307230}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"InsertIt"}},"batch":{"id":"6b38f826-f801-4885-9a41-cc20efb0e01f","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\3. Basic Data Structures\\Insert_it.cpp"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Sorted","group":"HackerRank - Assignment 01 | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/assignment-01-a-basic-data-structure-a-batch-05/challenges/sorted-2-2","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"id":1720452186610,"input":"3\n5\n2 4 6 7 10\n8\n1 100 101 120 120 121 1000 1000\n4\n100 1 102 12\n","output":"YES\nYES\nNO\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"Sorted"}},"batch":{"id":"e3d0163d-cb58-4d18-9f49-f40529f81c89","size":1},"srcPath":"f:\\Tutorials\\Video Tutorials\\Phitron\\3. Basic Data Structures\\Sorted.cpp"}

‎.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}

‎Insert_it.cpp

Whitespace-only changes.

‎Sorted.bin

51.2 KB
Binary file not shown.

‎Sorted.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int t;
7+
cin >> t;
8+
while (t--)
9+
{
10+
int n;
11+
cin >> n;
12+
int a[n];
13+
bool flag = true;
14+
for (int i = 0; i < n; i++)
15+
{
16+
cin >> a[i];
17+
}
18+
19+
for (int i = 1; i < n; i++)
20+
{
21+
if (a[i - 1] > a[i])
22+
{
23+
flag = false;
24+
break;
25+
}
26+
}
27+
28+
if (flag)
29+
cout << "YES" << endl;
30+
else
31+
cout << "NO" << endl;
32+
}
33+
34+
return 0;
35+
}

‎Sorted.exe

51.2 KB
Binary file not shown.

‎input.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
3
12
5
2-
1 2 3 4 5
3+
2 4 6 7 10
4+
8
5+
1 100 101 120 120 121 1000 1000
6+
4
7+
100 1 102 12

‎output.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
YES
2+
YES
13
NO

0 commit comments

Comments
 (0)