Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT

Choose two positions i < j with j − i ≥ 3 in [5, -4, 3, 8, -6, 2, 7]. What is the largest possible product a[i] · a[j]?

  1. A. 56
  2. B. 62
  3. C. -48
  4. D. 57

Correct answer: A. 56

For the two-large-negatives case the best product can come from two negatives far apart; fix j and track the most positive and most negative values among indices at least d behind. Restricting to adjacent positions, or lowering the required distance, changes the answer.

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

Exams that ask this topic