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]
4 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]4 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
How do say phone in French?
olga_2 [115]

Answer:

téléphone

Explanation:

thats how you say phone in French also you can go on Google translate or word reference to translate words.

6 0
4 years ago
Read 2 more answers
your own choice Identify an organisation of whether factual of fiction with the following Consideration:The three best os to int
DedPeter [7]

Answer:

sorry dont know

Explanation:

7 0
3 years ago
Contagem progressiva e regressiva usando estrutura condicional enquanto no visualg
lana [24]
Girls are so evil nowadays
6 0
3 years ago
What will be the value of x after the following code is executed? int x = 10; do { x *= 20; } while (x &lt; 5); A. 10 B. 200 C.
dezoksy [38]

Answer:

Option B is the correct answer.

Explanation:

  • In the above code, the loop will execute only one time because the loop condition is false and it is the Do-While loop and the property of the Do-while loop is to execute on a single time if the loop condition is false.
  • Then the statement "x*=20;" will execute one and gives the result 200 for x variable because this statement means "x=x*20".
  • SO the 200 is the answer for the X variable which is described above and it is stated from option B. Hence it is the correct option while the other is not because--
  1. Option A states that the value is 10 but the value is 200.
  2. Option C states that this is an infinite loop but the loop is executed one time.
  3. Option D states that the loop will not be executed but the loop is executed one time
6 0
3 years ago
Read 2 more answers
Using a Mouse
MariettaO [177]
I think it might be A. mouse sorry if I get it wrong tho hope it’s right.
7 0
3 years ago
Read 2 more answers
Other questions:
  • what important technology has done the most to allow small businesses a change to compete with larger international companies?
    5·1 answer
  • business ethics chapter 7 jordan, a software engineer, is responsible for maintaining the private piece of his company's interne
    15·1 answer
  • 6.
    15·1 answer
  • An example of a historical challenge of STAMIS is
    13·2 answers
  • Which option marks all modification made within a document? Review Comment Track Changes Balloons
    15·2 answers
  • When you tap or click the ____ button for a selected graphic, Word provides options for changing how a graphic is positioned wit
    5·1 answer
  • What is the difference between C and C++. If I know C, will it be hard to lean C++?
    15·1 answer
  • A professional photographer working for a top newspaper would like control over the quality and editing
    14·2 answers
  • Weegee confused. <br><br> Why is weegee.org kitty website...?
    8·2 answers
  • Can’t be opened because apple cannot check it for malicious software.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!