Given an array, we need to modify values of this array in such a way that sum of absolute differences between two consecutive elements is maximized. If the value of an array element is X, then we can change it to either 1 or X.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains an integer N denoting the size of the array A.

The second line of each test case contains N space separated integers denoting elements of the array A[ ].

**Output:**

Print the maximum sum of adjacent differences after modifying the array for each test case in a new line.

**Constraints:**

1<= T <=100

1<= N <=100000

1<= A[ ] <=100000

**Example:**

**Input:**

1

5

3 2 1 4 5

**Output:**

8

Explanation:

Modified array: 3 1 1 4 1

ans = | 1 - 3 | + | 1 - 1 | + | 4 - 1 | + | 1 - 4 | = 8

Author: sujnesh

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

madhursengar24 | 86 |

PiyushPandey4 | 617 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 448 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.