Write a function second_largest(arr) that finds the second largest element in an array. You may assume the array has at least two distinct elements.
Example:
Input: arr = [5, 2, 8, 1, 9, 3]
Output: 8
Constraints:
Test Cases
Test Case 1
Input:
[5, 2, 8, 1, 9, 3]Expected:
8Test Case 2
Input:
[10, 20, 30]Expected:
20Test Case 3
Input:
[1, 1, 2, 2, 3]Expected:
2+ 2 hidden test cases