Find the Wrong Digit Index in a Sum
You are given three non-negative integers: num1, num2, and givenSum.
Compare the correct result of num1 + num2 with givenSum digit by digit in base 10, starting from the least significant digit.
The ones place is index 0, the tens place is index 1, and so on. If one number has fewer digits than the other, treat the missing higher digits as 0 when comparing.
Return the index of the first mismatching digit. Return -1 if every digit matches.
Complete the function findWrongDigitIndex in the editor below.
findWrongDigitIndex has the following parameters:
long num1: the first addendlong num2: the second addendlong givenSum: the sum to compare against
Returns
int: the first mismatching digit index, or -1 if the sum is correct.
1Example 1
The correct sum is 20. The ones digit differs immediately: 0 versus 9.
2Example 2
The provided sum is correct, so there is no mismatching digit.
Constraints
Limits and guarantees your solution can rely on.
0 <= num1, num2, givenSum <= 10^18- Use base-10 digit comparison from least significant to most significant position.