Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5604 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 799 |

@sriramgoparaju99 | 737 |

@Manikanta punnam | 629 |

@rdakka | 606 |

@prankursharma31 | 597 |

@praveenbgp6 | 546 |

@sanskar94511 | 531 |

@purohitmn02 | 529 |

@yashkaril4 | 517 |

@abhikarshgupta | 474 |

@rohitgarg2825 | 464 |

Complete Leaderboard |

Given two arrays **a[]** and **b[]** respectively of size **n** and **m, **the task is to print the count of elements in the intersection (or common elements) of the two arrays.

For this question, the intersection of two arrays can be defined as the set containing distinct common elements between the two arrays.

**Example 1:**

Input:5 3 89 24 75 11 23 89 2 4Output:1Explanation:89 is the only element in the intersection of two arrays.

**Example 2:**

Input:6 5 1 2 3 4 5 6 3 4 5 6 7Output:4Explanation:3 4 5 and 6 are the elements in the intersection of two arrays.

**Your Task:**

The task is to complete the function **NumberofElementsInIntersection()** which takes 4 inputs ie- array a, array b, n which is the size of array a, m which is the size of array b. The function should return the count of the number of elements in the intersection.

**Expected Time Complexity: **O(n + m).

**Expected Auxiliary Space: **O(min(n,m)).

**Constraints:**

1 ≤ n, m ≤ 10^{5}

1 ≤ a[i], b[i] ≤ 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Intersection of two arrays

...