Skip to content
Get started

Counting complement pairs

In the array [2, 4, 3, 5, 6, 4, 1, 7], how many unordered pairs of distinct positions (i,j)(i, j) with i<ji < j have array[i]+array[j]=8\text{array}[i] + \text{array}[j] = 8?

Show hints (2)+
  1. For each element, count how many earlier elements equal its complement 8−x8-x.
  2. Watch the two 4s: they form a valid pair since they sit at different positions.

Answer

Reveal answer →

4

Create a free account to see the full worked solution and track your progress.

Interview format: Market Maker, Systematic & Data-Driven Trading

Related questions