Given two integers N and X. The task is to print the absolute difference between the first X and last X digits in N. Considering the number of digits is atleast 2*x.
Input: N = 21546, X = 2 Output: 25 The first two digit in 21546 is 21. The last two digit in 21546 is 46. The absolute difference of 21 and 46 is 25. Input: N = 351684617, X = 3 Output: 266
- Store the last x digits of the number in last.
- Find the number of digits in the number.
- Remove all the digits except the first x.
- Store the first x integers of the number in first.
Below is the implementation of the above approach:
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
- Minimum absolute difference between N and any power of 2
- Maximum absolute difference in an array
- Minimize the absolute difference of sum of two subsets
- Minimum absolute difference between N and a power of 2
- Closest Palindrome Number (absolute difference Is min)
- Count pairs in an array such that the absolute difference between them is ≥ K
- Pair of prime numbers with a given sum and minimum absolute difference
- Absolute Difference of all pairwise consecutive elements in an array
- Largest subset where absolute difference of any two element is a power of 2
- Check if array can be divided into two sub-arrays such that their absolute difference is K
- Absolute difference between sum and product of roots of a quartic equation
- Minimum absolute difference of a number and its closest prime
- Predict the winner of the game on the basis of absolute difference of sum by selecting numbers
- Partition the array into two odd length groups with minimized absolute difference between their median
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.