The Fire Rises

0

0 votes
Ad-Hoc, cakewalk, Very-Easy
Problem

"It's a bird, it's a plane, it's Superman!"

Clark Kent was chilling with Lois, when suddenly Lex Luthor put his new plan to conquer Metropolis in action. Lex has set n buildings on fire, so that Superman is distracted while he carries out a robbery in S.T.A.R Labs.

However, Lex didn't plan the fires very well, so the buildings that his henchmen have set fire to all lie on the same horizontal straight line. Now, Superman can put out all the fires in any order, but he wishes to minimize the damage, so he wants to travel the smallest distance possible. Help Superman find this smallest distance.

Superman can start putting out fires at ANY building and end at ANY building.

Only the distances between buildings are counted.

INPUT:

The first line of input contains the number of test cases, t.

Each test case consists of 2 lines.

The first line of each test case contains the number of buildings (n) Lex has set fire to.

The second line contains the x - coordinate of n buildings (x1, x2, ... xn)

OUTPUT:

For each test case, print the smallest distance that Superman has to travel so as to put out the fires in all the buildings.

CONSTRAINTS:

1 <= t <= 100

1 <= n <= 10000

1 <= xi <= 1000000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, Superman can start from building with x = 2, then go to x = 3, then x = 5 and then end at x = 7. The total distance travelled will be 5.

In the second test case, Superman can start from building with x = 1, go to x = 2, 3, 4 and then end at x = 5 Total distance travelled will be 4.

Editor Image

?