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
What happens? In word 2016 when the home ribbon tab is clicked on ?
RideAnS [48]

When you clicked on the ribbon tab in word 2016, you'd be brought to the home tab, where all of the basic controls are displaced for you to see.

Hope I could help! :)

5 0
3 years ago
Read 2 more answers
What is the best approach to testing a website
Ronch [10]

A vital part of any website project is the quality assurance stage. Prior to launch, final QA testing ensures that your site is working according to your expectations and that your site users won’t be frustrated with any non-functioning pages.

7 0
3 years ago
There was a thunderstorm in your area and the power went out.
Anna71 [15]

Answer:

A) The law requires that when I get to an intersection, I have to allow a right-of-way to the vehicles approaching from the right.

B) if there is an officer directing traffic, then I have to follow the directives of the officer.

Cheers!

8 0
3 years ago
The backbone networks of the Internet are typically owned by long-distance telephone companies called
Aneli [31]

Answer:

network service providers

Explanation:

The backbone networks of the Internet are typically owned by long-distance telephone companies called network service providers.

A network service provider can be defined as a business firm or company that is saddled with the responsibility of leasing or selling bandwidth, internet services, infrastructure such as cable lines to small internet service providers.

5 0
3 years ago
Which social media platform provides filters that alter the user's face by smoothing and whitening skin, changing eye shape, nos
Olegator [25]

Answer: Snap-chat

Explanation:

is a social media platform application developed for mainly sharing of photos with the use of some special filters which are able alter how the person looks. examples of such filters are filters that alter the user's face, smoothing and whitening the users skin, changes the eye shape of the user, alters the nose size and jaw profile of the individual using the app. Snap chat has become a photo favorite for many young people today and celebrities alike.

5 0
3 years ago
Other questions:
  • In a packet voice communications system, a source transmits packets containing digitizedspeech to a receiver. Because transmissi
    6·1 answer
  • Truncation is a keyword search technique that helps you find useful variations of a term or terms. You want to find books on the
    5·1 answer
  • Describe an application or a situation in which it is not convenient to use a linked list to store the data of the application
    12·1 answer
  • Question Workspace Check My Work Copying computer software, video games, movies, or music without paying the producer for them i
    11·1 answer
  • Which of these is one of the primary concerns for protecting your family when online?
    9·2 answers
  • 60 POINTS!! WILL MARK BRAINLEST!!
    11·1 answer
  • Adam's interview with the hiring manager is going well. However, he wants to ensure that his skills and work history are memorab
    6·1 answer
  • 30 POINTS PLS HELP AND DONT PUT ANYTHING IF U DK PLS
    5·1 answer
  • True or False The two types of general construction projects are residential for homes or dwellings and commercial for a commerc
    7·1 answer
  • #It helps in the proper function ing of computer hardware.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!