-
Notifications
You must be signed in to change notification settings - Fork 183
/
15 - Day 14 - Scope.cs
56 lines (43 loc) · 1.12 KB
/
15 - Day 14 - Scope.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ========================
// Information
// ========================
// Direct Link: https://www.hackerrank.com/challenges/30-scope/problem
// Difficulty: Easy
// Max Score: 30
// Language: C#
// ========================
// Solution
// ========================
using System;
using System.Linq;
class Difference {
private int[] elements;
public int maximumDifference;
// Add your code here
public Difference(int[] elements) {
this.elements = elements;
}
public int computeDifference() {
int maxElement = elements[0];
int minElement = elements[0];
for (int i = 0; i < elements.Length; i++) {
if (elements[i] < minElement) {
minElement = elements[i];
}
if (elements[i] > maxElement) {
maxElement = elements[i];
}
}
maximumDifference = Math.Abs(maxElement - minElement);
return maximumDifference;
}
}
class Solution {
static void Main(string[] args) {
Convert.ToInt32(Console.ReadLine());
int[] a = Console.ReadLine().Split(' ').Select(x = >Convert.ToInt32(x)).ToArray();
Difference d = new Difference(a);
d.computeDifference();
Console.Write(d.maximumDifference);
}
}