Skip to content

Commit

Permalink
Check if two arrays are equal or not.cpp
Browse files Browse the repository at this point in the history
Program Check if two arrays are equal or not in c++.
  • Loading branch information
Sonu589 authored Oct 4, 2021
1 parent 51048e8 commit fa37258
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions CPP/Check if two arrays are equal or not.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Program Check if two arrays are equal or not >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/*
Given two array of same size, find out if given arrays are equal or not.
Note: Two arrays are said to be equal if both of them contain same set of elements, although arrangements (or permutation) of elements may be different.
Note : If there are repetitions, then counts of repeated elements must also be same for two array to be equal..
For example, if A = [11, 12, 13] and B = [12, 11, 13] then answer is 1 and
if A = [11, 12, 13, 12, 13] and B = [12, 11, 13, 12, 13] then answer is 1 and
if A = [11, 12, 13] and B = [12, 13] then answer is 0.
Complete the function below to accept two arrays as parameters and return the answer as above.
Input Format
The 1st line contains an integer M, the number of elements in A and B.
The 2nd line contains M integers separated by space.
The 3rd line contains M integers separated by space.
Output Format
Print 1 or 0 as per the condition.
Sample Input->>
3
11 12 13
12 11 13
Sample Output->>
1
*/

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Code Of Solution >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

int arraysEqualorNot(vector<int> A, vector<int> B) {
sort(A.begin(),A.end());
sort(B.begin(),B.end());
for (int i = 0; i < A.size(); i++)
{
if(A[i] != B[i]){
return 0;
}
}
return 1;
}

0 comments on commit fa37258

Please sign in to comment.