-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion_Tcs_CodeVita_SpecialArray.txt
More file actions
21 lines (20 loc) · 1.44 KB
/
Question_Tcs_CodeVita_SpecialArray.txt
File metadata and controls
21 lines (20 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Problem : Special Array
An array A is said to be special if all its elements are same. Given an array, your task is to convert the array to special array by performing some operations. The allowed operations are increment or decrement an element by 1. Your task is to find out the minimum number of operations needed to convert the given array to special with the constraint that the element of the special array is present in the original array.
Input Format:
First line starts with T, which is the number of test cases. Each test case contains:
Length of the array (N) Next line contains N spaced integers.
Output Format:
For each test case print the minimum number of operations needed to convert the array to special array. Take modulus of the result with 1000007.
Constraints:
1<=T<=10
1<=N<=10000
1<=Ai<=10000, where Ai represents the ith element in the array.
Sample Input and Output
SNo. Input Output
1 1
3 5
1 6 2
Explanation:
If we choose 1st element total 6 steps(0 steps for 1st element, 5 steps for 2nd element, 1 step for 3rd element) will be taken to convert the array to [1,1,1].
If we choose 2nd element total 9 steps(5 steps for 1st element, 0 steps for 2nd element, 4 steps for 3rd element) will be taken to convert the array to [6,6,6].
If we choose 3rd element total 5 steps(1 steps for 1st element, 4 steps for 2nd element, 0 steps for 3rd element) will be taken to convert the array to [2,2,2]