Given two numbers , find the minimum operations to be done to make two numbers same. In one operation a digit can be incremented or decremented by one.
Answers
Answered by
30
Answer:
During the first operation, any of the two numbers can be increased by one.
During the second operation, any of the two numbers can be increased by two.
During the third operation, any of the two numbers can be increased by three and so on.
Examples:
Input : n = 1, m = 3
Output : 3
Explanation:
Add 1 to n; n = 2
Add 2 to m; m = 5
Add 3 to n; n = 5
Both n and m are equal now
N of operations = 3
Input : n = 30, m = 20
Output : 4
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
Approach:
The approach used to solve the problem is the sum of N terms in an AP.
It is given by the formula
Similar questions