#404 Count of Common Elements in Array Prefixes
Two arrays containing numbers from 1 to N are given. For each of the N indexes, find the number of unique elements in the intersection of the sets formed by the first and second array prefixes.
Example:
1 2 3 5 4
5 3 7 4 1
Answer:
0 0 1 2 3
Here:
- At index zero there are no common elements among the currently available values: 1 in the first array and 5 in the second.
- At index one there are also none: 1,2 in the first array and 5,3 in the second.
- At index two: 1,2,3 in the first array and 5,3,7 in the second. The intersection contains 3, so write 1.
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor