← Back

Find the second largest element in an array.

Given an array of integers, find the second largest element.

Algorithm

  1. Initialize two variables, first and second, to -Infinity.
  2. Iterate through the array:
  3. Return or print the values.

Time Complexity

The time complexity of this algorithm is O(n), where n is the number of elements in the array.