Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: In the array [5, 8, 3, 7, 2], find the second-largest element.

  1. A. 8
  2. B. 5
  3. C. 3
  4. D. 7

Correct answer: D. 7

Sorted: 2, 3, 5, 7, 8, so the second largest is 7. The original second element is 8 (the maximum), the median is 5, and the second smallest is 3.

More Coding Interview Problems questions

Exams that ask this topic