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
Consider the language S*, where S = {a ab ba}.
Nezavi [6.7K]

Answer:

Check Explanation

Explanation:

A) the string (abbba) is not a word in this language because in this language, each b must preceded or followed by an a. Three consecutive b's are just not possible.

B) All the words with 3 letters in this language

aaa

aab

aba

baa

C) 5 words with four letters from this language. I'll write as many as possible to make things as easy as possible.

aaaa

aaab

aaba

baab

baba

baaa

abaa

abab

abba

D) This is the language of words without bbb, with every bb preceded and followed by an a (that is, no word can start or end wilth bb). All non-empty strings contain at least one a (so b and bb together are not allowed!).

Hope this Helps!!!

6 0
3 years ago
(PLEASE HELP!! I'll award brainiest!!)
Bas_tet [7]

Answer:

Repair

Have a good day

3 0
3 years ago
Read 2 more answers
Alice is an investor who has created a device controlled by an app that will water plants automatically. Alice has no experience
oksian1 [2.3K]

Answer:

3rd one

Explanation:

took test

5 0
3 years ago
Write a function definition for a function which takes one parameter and returns twice that parameter
dezoksy [38]

Answer:

The function in python is as follows:

def twice(num):

   return 2 * num

Explanation:

This defines the function; The function receives num as its parameter

def twice(num):

This returns twice of num

   return 2 * num

8 0
3 years ago
Please help me what is an example of a growing trend on social media
Marizza181 [45]

Answer:

B

Explanation:

8 0
3 years ago
Other questions:
  • To illustrate a point in a Word document with a simple chart, what command should you select
    6·2 answers
  • The sound cards is a digital to____________ converter.
    11·1 answer
  • Declare an array reference variable, week, and initialize it to an array containing the strings "mon", "tue", "wed", "thu", "fri
    15·1 answer
  • What is basic statement made up of​
    10·2 answers
  • "Create a Python program named detect_column_level_data_entry_errors. When complete, you will run this program to produce a diag
    11·1 answer
  • While doing online research you enter this keyword search with a truncation character: man* Which of the following would not be
    15·1 answer
  • Which operation on a pwc requires more than idle speed?
    8·1 answer
  • How do you check how much space is left in current drive?
    9·1 answer
  • Your development server is experiencing heavy load conditions. Upon investigating, you discover a single program using PID 9563
    5·1 answer
  • To reposition the legend to the left-hand side of a chart, click the _________ button, point to legend, click the right arrow ic
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!