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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- N digit numbers having difference between the first and last digits as K
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Count of numbers upto N having absolute difference of at most K between any two adjacent digits
- Generate all N digit numbers having absolute difference as K between adjacent digits
- Count numbers with same first and last digits
- Find first and last digits of a number
- Find the first and last M digits from K-th power of N
- Find the radii of the circles which are lined in a row, and distance between the centers of first and last circle is given
- Find the side of the squares which are lined in a row, and distance between the centers of first and last square is given
- Minimum digits to be removed to make either all digits or alternating digits same
- Nth positive number whose absolute difference of adjacent digits is at most 1
- Count of N-digit numbers with absolute difference of adjacent digits not exceeding K
- Count of N-digit numbers with absolute difference of adjacent digits not exceeding K | Set 2
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Absolute difference between sum and product of roots of a quartic equation
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Minimum absolute difference between N and a power of 2
- Number of possible permutations when absolute difference between number of elements to the right and left are given
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.