Tag Archives: scope

Hackerrank “30 Days of Code” Çözümleri – Day 14: Scope

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 14: Scope” sorusunun açıklaması ve çözümü. Bu soruda scope kavramına göz atmaya çalıştık.

► Hackerrank 30 Days of Code Çözümleri – Day 14: Scope: https://www.hackerrank.com/challenges/30-scope/problem

► Problem açıklaması:


Today we’re discussing scope. Check out the Tutorial tab for learning materials and an instructional video!

The absolute difference between two integers, a and b, is written as |a – b|. The maximum absolute difference between two integers in a set of positive integers, elements, is the largest absolute difference between any two integers in _elements.

The Difference class is started for you in the editor. It has a private integer array (elements) for storing N non-negative integers, and a public integer (maximumDifference) for storing the maximum absolute difference.


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. A 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 the editor reads in lines of input. The first line contains N, the size of the elements array. The second line has space-separated integers that describe the array.

Output Format

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

Sample Input

STDIN Function

—– ——–

3 __elements[] size N = 3

1 2 5 __elements = [1, 2, 5]

Sample Output