answer.
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]
2 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]2 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
Interactive media professionals are unique among other Information Technology professionals because they have very good job pros
Advocard [28]

Answer:

B.

Explanation:

Trust me.

3 0
2 years ago
In a situation where handicapped person can only input data into the computer using a stylus or light pen, which keyboard config
asambeis [7]
I think the best one is voice recognition keyboards.


Would perfect work there



Mark as brainliest
8 0
2 years ago
Read 2 more answers
One form of competition-based pricing is going-rate pricing, inwhich a firm bases its price largely on competitors' prices, with
Kobotan [32]

Answer:

Out of the four options , the option that is most suitable  is

option b. Cost, demand

<u>cost</u> or to <u>demand</u>

Explanation:

Going rate pricing is a form of competition based pricing. This pricing is commonly used for homogeneous products i.e., products with very minute distinction or variation among producers.

This type of pricing is based on setting price on the basis of the prevailing market trends in pricing of goods or services, so, the prices are largely based on the competition in the market rather than considering its own cost and demand.

8 0
2 years ago
When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
DochEvi [55]
What are the options?
3 0
2 years ago
Read 2 more answers
The piston engine uses the ________ to convert the reciprocating motion of the piston into rotary motion.
PSYCHO15rus [73]

The piston engine uses the crankshaft to convert the reciprocating motion of the piston into rotary motion.

<span>The crankshaft is used to convert reciprocating motion of the piston into rotary motion, while the conversion process is called torque, which is a twisting force. Aside from crankshaft, there are a total of four parts of the engine that work together in order to convert the reciprocating motion into rotary motion namely cylinder, or also called the chamber of the piston, the piston itself, and the connecting rod.</span>

5 0
2 years ago
Other questions:
  • Which references are updated when you copy the formula =$E6-MAX(H$1:J4)
    10·1 answer
  • If a stadium pays $20,000 for labor and $13,000 for parking, what is the stadium's profit margin if the game generates $206,000
    7·2 answers
  • Explain how buyers and sellers factor into setting the stock price for a company’s shares.
    13·1 answer
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • As in algebra, you can use brackets to override the order of operations Excel follows to perform formula calculations. True or f
    13·1 answer
  • Alyosha was explaining to a friend the importance of protecting a cryptographic key from cryptoanalysis. He said that the key sh
    10·1 answer
  • What happened if the offshore team members are not able to participate in the iterations demo due to timezone/infrastructure iss
    12·1 answer
  • (a) Show how to use (the Boolean formula satisfiability program) satisfiable num (and substitute) to find a satisfying assignmen
    9·1 answer
  • Write measurable performance objectives.Suppose that a trainer has identified as a generalgoal for a training module,"Able to fo
    13·1 answer
  • In this exercise we look at memory locality properties of matrix computation. Th e following code is written in C, where element
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!