Computer Science, asked by HIMANSHUKUNCHAL47470, 11 months ago

Write a function accordian(l) that takes as input a list of integer l and returns True if the absolute difference between each adjacent pair of elements alternates between increasing strictly and decreasing strictly.

Answers

Answered by monarchatharva1933
3

Answer:

Consider an array of integers, . We define the absolute difference between two elements, and (where ), to be the absolute value of .

Given an array of integers, find and print the minimum absolute difference between any two elements in the array. For example, given the array we can create pairs of numbers: and . The absolute differences for these pairs are , and . The minimum absolute difference is .

Answered by destroyerk71
0

Answer:

def accordian(x):

   l=[]

   for i in range(len(x)-1):

       k=abs(x[i+1]-x[i])

       l.append(k)

   

       

   return alternate(l)

def alternate(l):

   inc,dec=1,1

   i,j=0,1

   n=len(l)

   if l[j]>l[i]:

       flow='inc'

   else:

       flow = 'dec'

   if n==2 and l[i]!=l[j]:

       return True

   else:

       while(j<n):

           

           if(l[i]<l[j] and flow=='inc'):

               flow='dec'

               dec=dec+1

           elif(l[i]>l[j] and flow=='dec'):

               flow = 'inc'

               inc+=1

           else:

               return False

           i,j=i+1,j+1

       if(inc>=2 and dec>=2):

            return True

       return False

Explanation:

Similar questions