Skip to content

Practice Find Common Elements Between Two Arrays

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2956
LeetCode Problem

Find Common Elements Between Two Arrays

Problem Statement

Return [answer1,answer2]. answer1 counts indices in nums1 whose value occurs at least once in nums2; answer2 counts indices in nums2 whose value occurs at least once in nums1. Repeated values at different indices contribute separately.

Source: Find Common Elements Between Two Arrays on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [2,3,2], nums2 = [1,2]
Output
[2,1]

# Example 2

Input
nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
Output
[3,4]

# Example 3

Input
nums1 = [3,4,2,3], nums2 = [1,5]
Output
[0,0]

Constraints

n == nums1.length
m == nums2.length
1 <= n, m <= 100
1 <= nums1[i], nums2[i] <= 100

Related LeetCode Problems

Practice more problems similar to Find Common Elements Between Two Arrays.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.