You are given a string of length 2N consisting of only digits from 0 to 9. You can make a move to choose an arbitrary position and replace the digit in that position with any digit from 0 to 9.
Task
Determine the minimum number moves required to make the sum of the first N digits equal to the sum of the N digits that follow.
Note: 1-based indexing is used.
Example
Assumptions
Approach
Now, S = 911209
Therefore, the sum of S[1] to S[3] = 9 + 1 + 1 = 11 and the sum of S[4] to S[6] = 2 + 0 + 9 = 11.
Hence, the minimum number of moves required is 2.
Note: There can be other possible ways to achieve the answer, but we can not get the required result sum in less than 2 changes.
Function description
Complete the function solve provided in the editor. This function takes the following 2 parameters and returns the answer:
Input format
Note: This is the input format you must use to provide custom input (available above the Compile and Test button).
Output format
For each test case, print the answer in a new line.
Constraints
1≤T≤10
1≤N≤105
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
The first line contains the number of test cases, T = 1.
The first test case
Given
Approach
Now, S = 4325.
Thus the sum of S[1] to S[2] = 4 + 3 = 7 and the sum of S[4] to S[6] = 2 + 5 = 7.
Hence, the minimum number of moves required is 1.
Note: There can be other possible ways to achieve the answer but we cannot get the required result in less than 1 change.