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
yulyashka [42]
3 years ago
8

we are given an array a consisting of n distinct integers. we would like to sort array A into ascending order using a simple alg

orithm. First we divide it into one or more slieces ( a slice is a contiguous sub array. Then we sort each slice. After that, we join the sorted slices in the same order. Write a function solution that returns the max number of slices for which the algorithm will return a correctly sorted array

Computers and Technology
1 answer:
marta [7]3 years ago
4 0

Answer:

Check the explanation

Explanation:

the js code is as follows

function count_max_group(ar) {

if (ar.length < 2) return ar.length; // if no of elements are 2 then max groups are 2

let st = [0]; // stack to store the groups

for (let i = 1; i < ar.length; i++) {

if (ar[i] >= ar[i - 1]) st.push(i); // pushing elements if if ar[i] is greater than the previous element

for (let j = i; j > 0 && ar[j] < ar[j - 1]; j--) { // finding the max number of grps

swap(ar, j, j - 1); // swapping

if (j <= st[st.length - 1]) st.pop();

}

}

return st.length;

}

function swap(a, i, j) { // function to swap two variables

let t = a[i];

a[i] = a[j];

a[j] = t;

}

//sample solutions

console.log("the sample solutions are\n");

console.log("[2,1,6,4,3,7]\n");

console.log(count_max_group([2,1,6,4,3,7]));

console.log("[4,3,2,6,1]\n") ;

console.log(count_max_group([4,3,2,6,1]));

console.log("[2,4,1,6,5,9,7]\n");

console.log(count_max_group([2,4,1,6,5,9,7]));

You might be interested in
Which input and output pair is correct for a bicycle?
mrs_skeptik [129]

Answer:

I'm pretty sure its B.

Explanation:

Input: Force is applied to the pedals by the rider's feet then..

Process: the chain and gear system convert the energy to cause...

Output: the rear wheels to turn and make the bike go foward

6 0
3 years ago
Which software documentation guideline did the IEEE establish?
Tomtit [17]

Answer:

B

Explanation:

I am big brain

8 0
2 years ago
Read the following scenario:
Fofino [41]

Answer:

I think it is the second answer choice honestly

Explanation:

I'm gonna say either the first one or second one because the word film has something to with behind the scenes work not being an actor.

8 0
2 years ago
Read 2 more answers
The Beaufort Wind Scale is used to characterize the strength of winds. The scale uses integer values and goes from a force of 0,
TEA [102]

Answer:

ranforce = randi([0, 12]);

if (ranforce == 0)

     disp('There is no wind')

else  if(ranforce>0 && ranforce <7)

     disp('There is a breeze')

else  if(ranforce>6 && ranforce <10)

     disp('This is a gale')

else  if(ranforce>9 && ranforce <12)

     disp('It is a storm')

else  if(ranforce==12)

     disp('Hello, Hurricane!')

end

Explanation:

<em>Replace all switch case statements with if and else if statements.</em>

<em>An instance is:</em>

<em>case {7,8,9}</em>

<em>is replaced with</em>

<em>else  if(ranforce>9 && ranforce <12)</em>

<em>All other disp statements remain unchanged</em>

5 0
2 years ago
You type a complex formula in cell A20. You would like to make the same calculation in cells B20 through H20. To be efficient, y
fomenos

Answer:

Use autofill

Explanation:

In excel "autofill" is used to fill data in cells, which follows the pattern or logic applied in other cells. To apply same calculation of A20 in B20 to H20, we use autofill technique. Instead of copy pasting, or manually entering the complex formula this method is more suitable.  

4 0
3 years ago
Other questions:
  • Robin maintains a web page for updating the metro timings in the city. He would like the website to display the present day's sc
    6·1 answer
  • ?the single most effective security measure for digital devices is to password protect access to them.
    5·1 answer
  • In step 2 of the mail merge process you must be prepared to
    6·2 answers
  • Study and compare the tables and draw conclusions.
    13·1 answer
  • Imagine you are building an ATM system; list at least 6 application domains for the system. That is, in which context is the sys
    13·1 answer
  • What is the output of the C++ codeabove?
    14·1 answer
  • HELP!!!!!!!
    8·1 answer
  • Is e commerce a challenge or opportunity to the freight forwarder
    8·1 answer
  • You must configure a certificate authority on your network to use EFS. True or False?
    5·1 answer
  • Which three options below describe typographic hierarchy?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!