Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many index pairs i < j of [1, 2, 3, 4, 6, 6] satisfy a[i] * a[j] = a[i] + a[j]?

  1. A. 1
  2. B. 3
  3. C. 0
  4. D. 2

Correct answer: C. 0

The equation xy = x + y rewrites as (x-1)(y-1) = 1, so only (2,2) and (0,0) qualify. Here the single 2 cannot pair with itself, so the count is 0.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic