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
Lucas wants to expand his vocabulary to better understand the sentence below. The insidious burglar moved through the house unhe
olga nikolaevna [1]

Answer:

B unheard & unseen

Explanation:

3 0
3 years ago
Read 2 more answers
How did mark watney survive the accident
VladimirAG [237]
.............. one second
5 0
3 years ago
Jennifer has been hired as a temporary employee at a local college. She is given a username and password to access certain parts
gulaghasi [49]

LAN (Local Area Network)

<span>Basically, to be precise, Intranet is an extension of LAN in which IP services like HTTP, TCP/IP and several other standard protocols are added. Intranet is a private internet network that is used to add internet like services in an internal LAN.</span>

4 0
3 years ago
Read 2 more answers
What variation of a dictionary attack involves a dictionary attack combined with a brute force attack, and will slightly alter d
Galina-37 [17]

Answer:

D) Hybrid Attack

Explanation:

This type of  attack is a blend of both a dictionary and brute force attack. The meaning of this is, while a dictionary attack method would capture a wordlist of passwords, the brute-force attack would be applied to each of  password captured.

6 0
3 years ago
What was bill gates first operating system he created?
vagabundo [1.1K]
Microsoft windows was his first

3 0
3 years ago
Other questions:
  • ISBN-13 is a new standard for identifying books. It uses 13 digits d1d2d3d4d5d6d7d8d9d10d11d12d13. The last digit d13 is a check
    9·1 answer
  • When reading a ____ language, we use our understanding of the richness of the language's vocabulary to extract the meaning. geop
    10·1 answer
  • A base class named Garden contains a private field width and a property public int Width that contains get and set accessors. A
    11·1 answer
  • Which of the following is something that scientists often seek by using computer models and simulations?
    8·2 answers
  • Which of the following scenarios is an example of irrelevant media?
    11·1 answer
  • Pride Group of Companies is making tremendous profits in different categories of electronic goods. The group of managers have to
    12·1 answer
  • Can somebody tell me the Minecraft command to clear an entire world and destroy every block if u Dunno please don’t answer &gt;-
    13·1 answer
  • 1. Who was the first lady programmer?​
    14·2 answers
  • Which of the following is an operating system?<br> MacBook Air<br> Windows 10<br> Dell
    13·2 answers
  • Classes that depend on field names from parent classes are said to be ____ because they are prone to errors.Group of answer choi
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!