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
What is a quasi vpn?
Natasha2012 [34]

Answer:

i don't think there is such thing as a quasi vpn

Explanation:

6 0
3 years ago
The best way to share criticism is to ______. a. write it in the break room b. talk it about with all your coworkers c. talk abo
ICE Princess25 [194]

Answer:

C.

Explanation:

6 0
3 years ago
Read 2 more answers
Which are types of lines? Choose three answers.
alekssr [168]
Straight
Curvilinear
Rectilinear
7 0
3 years ago
What are the business drivers of cloud computing?(Choose all that apply.)
Xelga [282]

Answer:  The applicable answers are b, c, and d.

Explanation:

When a company decides to hire the services of a cloud computing service provider, instead of investing in purchasing the resources needed in order to match its needs, as the cloud model is based on the concept "pay as you go", it allows to maximize the costs efficiency, and at the same time, gives the company the choice to define what type of steps are needed to grow, and when it is advisable to go beyond.

Finally, as it is possible to expand the services hired on the fly very easily, it is a very good way to be sure that it will never ran out of resources, no matter that future needs could be.

Actually, the only answer that is wrong is a) because it happens just the opposite: Cloud services allow to decrease time to market substantially.

7 0
3 years ago
Does anyone play fortnite i want to be gifted vbucks please my epic is Springtrap_locks thx means a lot to me
Paladinen [302]

Answer:

This is not what this platform is supposed to be used for

Explanation:

Fortnite isnt a real game lol get a life

3 0
3 years ago
Other questions:
  • The pseudoinstructions that are available in an assembly language programming environment usually found in the Select one: a. CP
    6·1 answer
  • Fill in the blank - A generation of social-oriented, physical games such as the _______ Wii console, emerged in the late 2000s,
    15·1 answer
  • Research the disadvantages of the computer and explain them.​
    15·1 answer
  • Most graphics software uses a process called pixel _________ to create new pixels by averaging the colors of nearby pixels.â
    6·1 answer
  • OSHA requires training for employees on the hazards to which they will be exposed.
    12·2 answers
  • Why is removing presentation-oriented markup from one's html document considered to be a best practice?
    14·1 answer
  • Xavier would like to change the sort options for his contacts. In which tab will he find the Arrangement command group?
    6·1 answer
  • A painting company has determined that for every 115 square feet or wall space, one gallon of paint and eight hours of labor wil
    11·1 answer
  • What does digital mean, in the term of computer science.
    11·1 answer
  • A. Get a value for x from the user.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!