Three Array Target Sum
MediumPython 3ArraysHash tables
You are given three integer arrays a, b, c and an integer target. Taking exactly one element from each array, find every triple (x, y, z) with x from a, y from b, z from c such that x + y + z == target.
Return the list of triples [x, y, z]. Each distinct combination of positions counts separately, so if a value repeats in an array the corresponding triples repeat too. The order of the returned triples does not matter.
Constraints: - arrays may contain duplicates and may be empty
Examples:
a = [1, 2, 3, 3], b = [2, 3, 3, 4], c = [1, 2, 2, 2], target = 7
-> 20 triples: [2, 4, 1], [3, 3, 1] (x4), and for each of the three 2's in
c: [1, 4, 2], [2, 3, 2] (x2), [3, 2, 2] (x2)a = [1], b = [1], c = [1], target = 3 -> [[1, 1, 1]] a = [1], b = [1], c = [1], target = 4 -> [] a = [], b = [1], c = [1], target = 2 -> []
Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.
Loading the editor…