Challenge: Check if the Given Arrays are Disjoint

If you are given two arrays, arr1 and arr2, can you check if these arrays are disjoint? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.

Problem Statement

In this problem, you have to implement the isDisjoint() function to check whether two given arrays are disjoint or not. Disjoint arrays mean that their intersection returns nothing or there are no common elements in them. The assumption is that there are no duplicate elements in each array. An illustration is also provided for your understanding.

Function Prototype:

boolean isDisjoint(int []arr1,int[]arr2);

Here, arr1 and arr2 are integer arrays.

Output:

It returns true if arr1 and arr2 are disjoint, or else it returns false.

Sample Input

arr1 = [9,4,3,1,-2,6,5]
arr2 = [7,10,8]

Sample Output

true

Explanation

arr1 and arr2 have no common elements, so both of them are disjoint arrays.

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