14: Scope(python)

                                 Scope(python)



Task
Complete the Difference class by writing the following:

  • A class constructor that takes an array of integers as a parameter and saves it to the  instance variable.
  • computeDifference method that finds the maximum absolute difference between any  numbers in  and stores it in the  instance variable.

Input Format

You are not responsible for reading any input from stdin. The locked Solution class in your editor reads in  lines of input; the first line contains , and the second line describes the  array.

Constraints

  • , where 

Output Format

You are not responsible for printing any output; the Solution class will print the value of the  instance variable.

Solution:

class Difference:
    def __init__(self, a):
        self.__elements = a


        self.__elements = a
        self.maximumDifference = 0

    # Add your code here
    def computeDifference(self):
        l = len(a)
        for i in range(0, l):
            for j in range(i + 1, l):
                difference = abs(a[i] - a[j])
                self.maximumDifference = max(difference, self.maximumDifference)
# End of Difference class



# End of Difference class

_ = input()
a = [int(e) for e in input().split(' ')]

d = Difference(a)
d.computeDifference()

print(d.maximumDifference)

Comments

Popular posts from this blog

15: Linked List(python)