P23 solution and helper list intersect function