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
Name the character encoding standard that enables up to 128 different commonly used characters,
Lelechka [254]

Answer:

ASCII character set.

Explanation:

ASCII is an acronym for American Standard Code for Information Interchange and it was developed from a telegraph code. It is typically a character encoding standard that comprises of seven-bit (7-bit) set of codes.

ASCII character set is the character encoding standard that enables up to 128 different commonly used characters, numbers and symbols to be used in electronic communication systems. The ASCII character set is only used for encoding English language and it comprises of both the lower case and upper case letters of the 26 alphabets, number 0 to 9 and symbols.

8 0
2 years ago
What is a primary feature of a digital video camera?
masha68 [24]
The primary feature of a digital video camera is to records video as digital signals. A digital video camera picture out as of live settings, encrypting it into information that can be definite or transcoded into electronic photographic media. A typical digital camera contains of a lens, image sensor, storing media and a number of other characteristics that can be also be initiated on other cameras such as scalable aperture, filters and flash. High feature images and digital video slides can be put in storage and replicated on a computer, CD or writable DVD or on the internet in deprived of any loss of quality.
4 0
3 years ago
References inserted initially as footnotes can be converted to endnotes through an option in the software.
Vesna [10]
The answer is A. True
3 0
2 years ago
Read 2 more answers
How do you find binary?
trasher [3.6K]

Answer:

To convert integer to binary, start with the integer in question and divide it by 2 keeping notice of the quotient and the remainder. Continue dividing the quotient by 2 until you get a quotient of zero. Then just write out the remainders in the reverse order.

Explanation:

3 0
2 years ago
What is a good computer i should get
algol [13]

Answer:

MacBook or a Dell computer in my opinion

Explanation:

5 0
2 years ago
Read 2 more answers
Other questions:
  • Find and record a set of instructions containing a repetition clause (e.g., instructions on a shampoo bottle, a recipe, etc.). H
    11·1 answer
  • Find the 65th percentile from the data. The data consist of class interval from 0-10, 10-20, 20-30, 30-40, 40-50, 50-60 and freq
    8·1 answer
  • Jim is expecting a very busy weekend at his store, so he sent the following e-mail to his employees: ALL EMPLOYEES MUST WORK THI
    6·1 answer
  • How are IP addresses usually written?
    7·1 answer
  • Why do Selection Sort and Insertion Sort’s outer loops run 11 iterations if there are 12 elements in the array?
    7·1 answer
  • Examples of email use that could be considered unethical include _____.
    14·2 answers
  • ¿En qué países se ha implementado un sistema de vigilancia a través de drones?, ¿qué aspectos positivos y negativos ha generado?
    13·1 answer
  • Ultraportable computers will often use ___ technology exclusively, even though their storage capacity is lower than that of a tr
    8·1 answer
  • 23. Convert the following to Megabytes<br> a) 2GB<br> b) 2056 Bytes-
    8·2 answers
  • Lab 8-1: Working with Boot Loader and Runlevels what is the root password
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!