The question Maximum single-sell profit returns one pair. How can you build upon any of the sub O(n^2) algorithm to find all pairs sorted by profit?
Ex.
values: scala.collection.immutable.Vector[Int] = Vector(1, 5, 10, -5, 0, -10, 15)
pairsAsc: Vector[(Int, Int)] = Vector((5,6), (3,6), (0,6), (0,2), (3,4))
gains: scala.collection.immutable.Vector[Int] = Vector(25, 20, 14, 9, 5)