Example 64: Compare Arrays

Learn how to compare two arrays.

Problem

Write a function that takes two 1-Dimensional arrays and their lengths as parameters and checks whether their contents are the same or not.

The function should return either 1 if both the arrays are the same or 0 if they are not.

Example

Input (arr1[], size1 arr2[], size2) Output
arr1 = {1, 2, 3, 4, 5}, 5
arr2 = {2, 3, 4, 5, 6}, 5
0
arr1 = {1, 2, 3, 4, 5}, 5
arr3 = {2, 4, 6, 8},4
0
arr1 = {1, 2, 3, 4, 5}, 5
arr4 = {1, 2, 3, 4, 5}, 5
1
arr2 = {2, 3, 4, 5, 6}, 5
arr3 = {2, 4, 6, 8}, 4
0

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.