Computer Science, asked by manideepikabonala01, 4 months ago

write an algorithm to find the maximum difference between the minimum and the maximum number of products available ​

Answers

Answered by anjalipawar5242
0

Answer:

rufirififkgogofofidufidg

Explanation:

dh ue8durhkrti4927hxjcjfhfhgghghhjcccvjshggkgfifigiyy4hfjj4hh569hjg4hghkghhdjflyyyyioppoaqeyvisaksaksham

Answered by vinod04jangid
1

Answer:

Explanation:

First discover the distinction among the adjoining factors of the array and save all variations in an auxiliary array diff[] of length n-1. Now this issues becomes locating the most sum subarray of this distinction array.Thanks to Shubham Mittal for suggesting this solution. Below is the implementation :

// C++ program to find Maximum difference

// between two elements such that larger

// element appears after the smaller number

#include <bits/stdc++.h>

using namespace std;

/* The function assumes that there are

at least two elements in array. The

function returns a negative value if the

array is sorted in decreasing order and

returns 0 if elements are equal */

int maxDiff(int arr[], int n)

{

// Create a diff array of size n-1.

// The array will hold the difference

// of adjacent elements

int diff[n-1];

for (int i=0; i < n-1; i++)

 diff[i] = arr[i+1] - arr[i];

// Now find the maximum sum

// subarray in diff array

int max_diff = diff[0];

for (int i=1; i<n-1; i++)

{

 if (diff[i-1] > 0)

  diff[i] += diff[i-1];

 if (max_diff < diff[i])

  max_diff = diff[i];

}

return max_diff;

}

/* Driver program to test above function */

int main()

{

int arr[] = {80, 2, 6, 3, 100};

int n = sizeof(arr) / sizeof(arr[0]);

// Function calling

cout << "Maximum difference is " << maxDiff(arr, n);

return 0;

}

How to write an algorithm in C++ for swapping 2 numbers ?

https://brainly.in/question/348918?msp_srt_exp=6

Write Factorial Flowchart and Algorithm in c++

https://brainly.in/question/46809384

#spj3

Similar questions