Assume that for a number of n digits, the value of each digit is from 1 to n and is unique. E.g. 32145 is a valid input number. Write a function that returns its inverse, where inverse is defined as follows Inverse of 32145 is 12543

I am not able to understand that how the inverse of the given number is being calculated

hi @ujjwalkashyap2002uk
Inverse is basically inverting the places of any number with its value.

For e.g…,
Before Inverse

Places --> 5 4 3 2 1
Value —> 3 2 1 4 5
After Inverse

Places --> 5 4 3 2 1
Value —> 1 2 5 4 3
Algo
1.Declare a Place variable that will keep track of the place number for which we are processing the work.
2.The value can be extracted by performing modulus operator on the given number.
3.In order to inverse the place and the number extracted in points 1 and 2 multiply the place with 10 ^ (rem - 1).
For e.g…, Place = 4 and rem = 3, then multiply place with 100 viz, ( 10 ^ (rem - 1)). 4.Add the number to the previous ans.

refer this code -->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.