
									 Problem
								
								
									 Solution
								
								
									 Submissions
								
								
							Second Largest Element in an Array
								Certification: Basic Level
								Accuracy: 32.26%
								Submissions: 31
								Points: 10
							
							Write a C++ function to find the second largest element in an array of integers.
Example 1
- Input: array = [5, 3, 8, 1]
- Output: 5
- Explanation:
    - Step 1: Find the largest element in the array (8).
- Step 2: Find the second largest element (5).
- Step 3: Return the second largest element.
 
Example 2
- Input: array = [10, 2, 7, 4]
- Output: 7
- Explanation:
    - Step 1: Find the largest element in the array (10).
- Step 2: Find the second largest element (7).
- Step 3: Return the second largest element.
 
Constraints
- 2 ≤ array length ≤ 10^4
- -10^5 ≤ array elements ≤ 10^5
- Time Complexity: O(n)
- Space Complexity: O(1)
Editorial
									
												
My Submissions
										All Solutions
									| Lang | Status | Date | Code | 
|---|---|---|---|
| You do not have any submissions for this problem. | |||
| User | Lang | Status | Date | Code | 
|---|---|---|---|---|
| No submissions found. | ||||
Solution Hints
- Traverse the array and keep track of the largest and second-largest elements.
- Handle edge cases where all elements are the same.
- Ensure the function works for the upper limit of the constraint.
