Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am using javascript or c++ /* * Complete the 'minimumMoves' function below. * * The function is expected to return an INTEGER. * The
I am using javascript or c++
/* * Complete the 'minimumMoves' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER_ARRAY a * 2. INTEGER_ARRAY m */
js:
function minimumMoves(a, m) { // Write your code here
}
c++:
int minimumMoves(vector
}
Andrea and Maria each have an array of integers. Andrea wants to change her array to match Maria's For each element of her array, she can increment or decrement one digit in one item in one move. How many moves will it take Andrea to match Maria's array. No reordering of the digits is allowed For example, consider two arrays: Andrea's [123, 543] and Maria's [321, 279]. For the first integer, Andrea can increment the 1 twice to achieve 3. The 2's are equal already. Finally, she decrements her 3 twice to equal 1. It took 4 moves to reach her goal. For the second integer, she decrements 5 three times, increments 4 three times and 3 six times. It took 12 moves to convert the second array element. In total, it took 16 moves to convert both values comprising the complete array. Function Description Complete the function minimumMoves in the editor below. The function must return the integer number of moves to convert Andrea's array to match Maria's. minimumMoves has the following parameter(s): ala[0O)....a. n-1]1: Andreas's array of integers mlm(0)1...mn-1]1: Maria's array of integers Constraints 1sns 105 1 s alil, mlils 10 The lengths of a and m are equal, la m| The elements alil and mlil have an equal number of digits. Input Format for Custom Testing Input from stdin will be processed as follows and passed to the function The first line contains an integer n, the size of the array a The next n lines each contain an element ali] where 0siStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started