Question: [Python Algorithm Question] - Array Q1. Please find the first and second largest element in the array You may assume the array has at least
[Python Algorithm Question] - Array
Q1. Please find the first and second largest element in the array You may assume the array has at least two unique elements
The solution has the complexity below and needs a comment for the logic
- Complexity:
- () time
- (1) space
![[Python Algorithm Question] - Array Q1. Please find the first and second](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4562f12ee2_87866f4562ea71ba.jpg)
The output should look like this,

def hobby(arr): Find the first and second largest element in the array You may assume the array has at least two unique elements Parameters arr : a list of integers Returns [the first largest element, the second largest element] : a list of two integers # Print arr_1 arr_2 arr_3 arr_4 II II II 11 [2, 3] [3, 2, 3] [2, 3, 5, -4] [2, 3, 5, -4, 9, 10, 20, 11] print(hobby(arr_1)) print(hobby(arr_2)) print(hobby(arr_3)) print(hobby(arr_4)) [3, 2] [3, 3] [5, 3] [20, 11]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
