Problem:
Score : 200 points

Problem Statement

You are given an integer sequence A of length N.
Find the maximum absolute difference of two elements (with different indices) in A.

Constraints

2 \leq N \leq 100

1 \leq A_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum absolute difference of two elements (with different indices) in A.

Sample Input 1

4
1 4 6 3

Sample Output 1

5

The maximum absolute difference of two elements is A_3-A_1=6-1=5.

Sample Input 2

2
1000000000 1

Sample Output 2

999999999

Sample Input 3

5
1 1 1 1 1

Sample Output 3

0

Solution in Scala (2.13.1) (judge verdict: Accepted)

import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val a = readLine().split(" ").map(_.toInt).toSeq

  def maxDiff(list: Seq[Int], max: Int): Int = {
    if (list.length > 2) {
      val i = (0 until list.length - 1).maxBy(i => (list(0) - list(i + 1)).abs)
      maxDiff(list.tail, math.max((list(0) - list(i + 1)).abs, max))
    } else
      math.max((list(0) - list(1)).abs, max)
  }

  println(maxDiff(a, 0))
}