Computer Science, asked by snehareddyb6, 16 days ago

Problem Statement Consider an array of non-zero positive integers inarr. Identify and print a number outnum based on the below logic Across each of the possible ways in which integers in inan can be sequentially arranged, identify the maximum absolute difference of adjacent values o The last and the first integers are adjacent Print outnum, the minimum value across the maximum differences identified above

Answers

Answered by monikagogoi000
1

Answer:

give me some example test cases....

Answered by Rameshjangid
0

Answer:- The differences are as follows with an example input 5,10,6,8. Please read full answer written below.

5,10,6,8:

5 - 10 =5 absolute maximum difference

10 - 6 = 4

6 - 8 =2

8 - 5 =3

Similarly, for other possible ways:

5,10,8,6 - absolute max difference = 5

5,6,8,10 - absolute max difference = 5

5,6,10,8 - absolute max difference = 4

5,8,6,10 - absolute max difference = 5

5,8,10,6 - absolute max difference = 4

10,5,6,8 - absolute max difference = 5

10,5,8,6 - absolute max difference = 5

10,6,5,8 - absolute max difference = 4

10,6,8,5 - absolute max difference = 5

10,8,6,5 - absolute max difference = 5

10,8,5,6 - absolute max difference = 4

6,5,10,8 - absolute max difference = 5

6,5,8,10 - absolute max difference = 4

6,8,5,10 - absolute max difference = 5

6,8,10,5 - absolute max difference = 5

6,10,5,8 - absolute max difference = 5

6,10,8,5 - absolute max difference = 4

8,5,6,10 - absolute max difference = 4

8,5,10,6 - absolute max difference = 5

8,6,5,10 - absolute max difference = 5

8,6,10,5 - absolute max difference = 5

8,10,5,6 - absolute max difference = 5

8,10,6,5 - absolute max difference = 4

The minimum value across the maximum differences is = 4

The algorithm to find trhe difference is as follows:-

def permutation(lst):

   if len(lst) == 0:

       return []

   if len(lst) == 1:

       return [lst]

   l = []

   for i in range(len(lst)):

      m = lst[i]

      remLst = lst[:i] + lst[i+1:]

      for p in permutation(remLst):

          l.append([m] + p)

   return l

data = [5,10,6,8]

got = []

for a in permutation(data):

   result = []

   for i in range(len(a)+1):

       if i > len(a)/2:

           result.append(abs(a[len(a)-1] - a[0]))

       else:

           result.append(abs(a[i] - a[i+1]))

   max_value = max(result)

   got.append(max_value)

print(list(set(sorted(got)))[0])

To know more about the given topic please go through the following

Link1:- https://brainly.in/question/14647516?

Link2:- https://brainly.in/question/17154348?

#SPJ3

Similar questions