Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

Hackerrank Day 14 scope 30 days of code solution

YASH PAL, 31 July 2024

In this HackerRank Day 14 scope 30 days of code problem, we have given A class constructor that takes an array of integers as a parameter and saves it to the instance variable. A computeDifference method finds the maximum absolute difference between any numbers and stores it in the instance variable. 

Day 14 scope Hackerrank 30 days of code solution

Problem solution in Python 2 programming.

	# Add your code here
    def computeDifference(self):
        maxDiff = 0
        arr = self.__elements
        for i in range(len(arr)):
            for j in range(i+1, len(arr)):
                if abs(arr[j] - arr[i]) > maxDiff:
                    maxDiff = abs(arr[j] - arr[i])
        self.maximumDifference = maxDiff

Problem solution in Python 3 programming.

        self.maximumDifference = 0
    
    def computeDifference(self):
        x = 101
        y = 0

        for item in self.__elements:
            if item < x:
                x = item
            if item > y:
                y = item
            

    
        self.maximumDifference = y - x 
	# Add your code here

Problem solution in java programming.

	// Add your code here
    public Difference(int[] nums) {
        elements = nums;
    }

    public void computeDifference() {
        Arrays.sort(elements);
        maximumDifference = elements[elements.length - 1] - elements[0];
    }

Problem solution in c++ programming.

	// Add your code here
    Difference(vector<int> arr){
        elements = arr;
        sort(elements.begin(), elements.end());
    }

    void computeDifference(){
        
        maximumDifference = abs(elements[elements.size()-1] - elements[0]);
    }

30 days of code coding problems solutions

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
©2025 Programming101 | WordPress Theme by SuperbThemes