Gustavo's Variation Analysis

0

0 votes
Very-Easy
Problem

Walter White and Jesse are famous all over the Albuquerque for making "blue crystals". Gustavo has now hired both of them to synthesize the product at his secret lab.

Being their boss, he records the quality of the product they make at the end of each day. Qualities are integers (both positive & negative numbers). On ith day, the quality of the product is Ai.

A variation is difference between qualities of product on any two days.

Gus has a quality record of N days. Now he needs to find out absolute value of maximum variation in quality obtained between any two days in his record.

"I like to think I see things in people. "

Can you help Gus Fring ?

enter image description here

INPUT

  • First line contains an integer T, the number of Test Cases.
  • Next T lines contains two lines each. First line has integer N. Second line has N space separated integers denoting qualities A1,2,...N

OUTPUT

  • Output should contain exactly T lines. Each line containing the answer (Absolute Value of the Maximum variation obtained).

CONSTRAINTS

  • 1 ≤ T ≤ 100
  • 2 < N ≤ 105
  • -109 ≤ Ai ≤ 109
  • Sum of N over all test cases ≤ 106
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In 2nd test case
All possible variations -
9-6=3
6-0=6
9-0=9
Maximum Variation= 9
Absolute Value=|9|=9

Editor Image

?