You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since your check for an element being in the intersection is for it's count in the flattened array of arrays to be equal to the number of total arrays, this doesn't work correctly if one of the arrays has repeated values.
Not very pretty, but still actually shorter than the current solution. Haven't given it a huge amount of thought, but I think it should have slightly better time complexity (goes over each array once rather than twice, still effectively O(n), could be improved further but not sure how you'd do it in one line), just a shame that it creates a new Set each iteration rather than mutating the initial one... Not sure how you'd do that elegantly in one line though.
Since your check for an element being in the intersection is for it's count in the flattened array of arrays to be equal to the number of total arrays, this doesn't work correctly if one of the arrays has repeated values.
e.g.
getIntersection([ 1, 1 ], [ 2, 3 ])
returns[ 1 ]
The text was updated successfully, but these errors were encountered: