Problem bank

Problem 243 of 333MediumCodingP243

Three trades that net to zero

  1. A list of signed trade quantities is given (positive for buys, negative for sells). Return every distinct triple of values that sums to zero, with no duplicate triples in the output. For example, [−1,0,1,2,−1,−4,3][-1, 0, 1, 2, -1, -4, 3] gives (−4,1,3)(-4, 1, 3), (−1,−1,2)(-1, -1, 2) and (−1,0,1)(-1, 0, 1). Beat the O(n3)O(n^3) brute force.