Topic: Hashing
Questions Successfully Completed: 1
1) Check if two arrays are equal or not | Easy |
Check if two arrays are equal or not
Time Complexity : O(n)
Space Complexity : O(n)
Questions
Input: N = 5 A[] = {1,2,5,4,0} B[] = {2,4,5,0,1} Output: 1 Explanation: Both the array can be rearranged to {0,1,2,4,5}
public static boolean check(long A[],long B[],int N)
{
Arrays.sort(A);
Arrays.sort(B);
for(int i=0;i<N;i++){
if(A[i]==B[i]){
continue;
}
else{
return false;
}
}
return true;
}
Thank you for Reading :)