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
1. Which sentence best expresses the main idea
Neko [114]
B is the answer

Hope this helps




3 0
3 years ago
Summary about Interface Design in system analysis
Anit [1.1K]

Answer:

Explanation:Systems Analysis

It is a process of collecting and interpreting facts, identifying the problems, and decomposition of a system into its components.

System analysis is conducted for the purpose of studying a system or its parts in order to identify its objectives. It is a problem solving technique that improves the system and ensures that all the components of the system work efficiently to accomplish their purpose.

Systems Design

It is a process of planning a new business system or replacing an existing system by defining its components or modules to satisfy the specific requirements. Before planning, you need to understand the old system thoroughly and determine how computers can best be used in order to operate efficiently.

System Design focuses on how to accomplish the objective of the system.

System Analysis and Design (SAD) mainly focuses on −

Systems

Processes

Technology

5 0
2 years ago
Which of these is true of blackhat and whitehat hackers?
earnstyle [38]

Answer:

Like all hackers, black hat hackers usually have extensive knowledge about breaking into computer networks and bypassing security protocols. They are also responsible for writing malware, which is a method used to gain access to these systems.

Explanation:

that's all. c:

5 0
3 years ago
Read 2 more answers
By default, what appears on your screen whenever a new email arrives?.
Troyanec [42]

By default, the appears on your screen whenever a new email arrives is a  Desktop Alert.

<h3>What is a Desktop Alert?</h3>

This is known to be a kind of  a notification that often shows on your desktop when a person is said to receive a new email message, a meeting request, or others.

Note that the Desktop Alerts need to be turned on by default and as such, By default, the appears on your screen whenever a new email arrives is a  Desktop Alert.

Learn more about Desktop from

brainly.com/question/7221406

#SPJ1

7 0
2 years ago
_____ are likely to support bigger government, social welfare programs, and legalized abortion.
Amanda [17]
Democrats are likely to support bigger government, social welfare programs, and legalized abortion.
8 0
3 years ago
Read 2 more answers
Other questions:
  • Store shelves are empty during periods of Excess Demand. What is another term for Excess Demand?
    8·1 answer
  • What finacial behaivor will typically lead to a low credit score
    8·1 answer
  • Which ofthe following is the most correct statement about the interestsection of the indirect plan for persuasion?
    8·1 answer
  • What are the three aspects to consider when taking and critiquing photograph?
    9·1 answer
  • Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its left and
    5·1 answer
  • What are the missing letters _A_TO_ ( 6 letters) a type of computer.
    13·2 answers
  • How do i make a comment on brainly?
    15·1 answer
  • Write short cut of<br> fully justified​
    7·1 answer
  • Adios brainly, you were sh.t sometimes, but you had your moments, wont be posting that much take my points away i d c
    6·2 answers
  • How does the variance as a measure of the dispersion of a data set relate to the measure of central tendency (i.e. mean)? What c
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!