Skip to content
Advertisement

Intersections of given sets with repeat of elements

Logic to count intersections in a given set is correct for no repetitive pattern, but for this set, the output count is wrong.

JavaScript

Code output is 8 Expected output to be 3

Advertisement

Answer

Try the following code. I use Math.min() for the second statement of for-loop to avoid IndexOutOfBounds error

JavaScript

Output is 3

Advertisement