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]
4 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]4 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
Rachel works in a bank. She wants to present the idea of implementing an IS to the management. How should Rachel describe the IS
Leni [432]

Rachael should describe information system to the management as an organized system that helps collect or gather, organize, track, store, manipulate, and analyze data to generate and distribute the information from gathered data to appropriate persons. The information generated is useful for managing your operations and making decisions. The efficient use of Information Systems will, without a doubt give a lot of opportunities to the company.

6 0
3 years ago
Read 2 more answers
All of the Internet in your country disappears. What happens next?
Talja [164]

Answer:

It is most likely that in a tech surrounded environment there would be an apacolypse, not necessarily a man hunting man apacolypse but it would cause a huge panic throughout that country because government could not communicate which is what leaves people with a safeplace.

Explanation:

please mark as brainliest xx hope it helps <3

if you really like this topic watch into the forest on netflix, it has the same premise except its not that internet disappears its electricity.

4 0
3 years ago
To find information on a network use a ____
igomit [66]

Answer:

circuit

Explanation:

4 0
2 years ago
What does a spam e-mail normally promise you?
nlexa [21]
The answer is a virus
7 0
3 years ago
Variables make it easier to do what?
defon
<span>D. Make changes to your code
Variables allow the ability to easily substitute numbers for other numbers.
</span>
8 0
3 years ago
Other questions:
  • to prevent long page load time for pages containing images. It is best to use a compress file formatlike jpeg as well as appropr
    6·2 answers
  • Explain why blocking ping (ICMP echo request) packets at an organization's edge router is not an effective defense against ping
    11·1 answer
  • Mathematical computations by a computer are faster than your quickest mathematical computations because the top speed of a neura
    13·1 answer
  • NEED HELP FAST
    13·2 answers
  • What are the advantages of homogenation
    5·1 answer
  • This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given p
    14·1 answer
  • Violations of security policies are considered to be a(n) __________ issue upon which proper disciplinary actions must be taken.
    7·1 answer
  • "background" software that helps the computer manage its own internal resources is called ________.
    5·1 answer
  • Which of the following prefixes would be best to use when measuring your own mass?
    15·1 answer
  • Identify the correct answer in each item. Write your answer on the blank provided before
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!