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

The output should look like this,

largest element in the array You may assume the array has at

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!