1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dmitriy555 [2]
3 years ago
15

Define a function max_n(arr, n) that takes in an array and an integer as arguments. Your function will then return the n largest

values from that array as an array containing n elements. It is safe to assume that arr will have at least n elements. The resulting array should have the largest number on the end and the smallest number at the beginning.
Computers and Technology
1 answer:
NikAS [45]3 years ago
4 0

Answer:

def max_n(arr, n):

   arr.sort()

   i = len(arr)-n

   return arr[i:]

Explanation:

Define a function called max_n that takes two parameters, an array and an integer

Sort the array

In order to get the last n largest values, we need to slice the array. To do that we need a starting point. Our starting point of slicing will be the "lentgh of the array - n". That means, if we start slicing from that index to the last in the sorted array, we will get the last n largest values.

Assume array is 10, 2, 444, 91 initially.

When we sort it, it becomes 2, 10, 91, 444

Now let's say we want last 2 largest values, our sliced array index should start from 2 and go until the end

i = 4 - 2 = 2 → arr[2:]  will return us 91 and 444

You might be interested in
Phil wants to make a dark themed superhero movie. What could be his target demographic
maria [59]

Answer:

d

Explanation:

i think, because it makes the most sense to me.

5 0
2 years ago
Read 2 more answers
What is Stefen Salvators mom name? For the tvd fans
jekas [21]

Answer:

Lillian "Lily" Salvatore

Explanation:

8 0
2 years ago
Read 2 more answers
Why is statistics important?
kenny6666 [7]

The answer is A.؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜؜

7 0
3 years ago
There are two kinds of emotions: positive and negative. True False
fgiga [73]

Answer:

False

Explanation:

There are many emotions the human brain can experience

6 0
2 years ago
Read 2 more answers
100 POINTS!!! PLEASE HELP ME
Ronch [10]

Answer:

1 web

2- invintory

3- spreadsheet

4-survey

Explanation:

hope it helps

5 0
2 years ago
Read 2 more answers
Other questions:
  • Few people will care if you use their image in a photograph without obtaining their consent. True False
    10·1 answer
  • In the game of economics, which player has the role of providing goods and services
    10·1 answer
  • When you are working on an unsaved document on a PC, where is the document temporarily saved?
    5·1 answer
  • In a ring-based system, procedure p is executing and needs to invoke procedure q. Procedure q's access bracket is (5,6,9). In wh
    15·2 answers
  • Types of operating systems
    5·2 answers
  • You have been using the same computer for several years. To extend its service life, you decide to upgrade the processor. You ch
    13·1 answer
  • hey guys just dropped some hot beats so go and follow me my user is the beats and comment if you would do that that would be gra
    11·1 answer
  • g Which of the following factors primarily determines how the Internet is used in different countries? A. local attitude to info
    6·1 answer
  • Which of the following screen elements is a horizontal bar that displays at the
    8·1 answer
  • You send a friend a private message about something personal that is going on with you. Without permission, she forwards your te
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!