Given three integers N, K and L. The task is to find the average of the first K digits and the last L digits of the given number N without any digit overlapping.
Input: N = 123456, K = 2, L = 3
Sum of first K digits will be 1 + 2 = 3
Sum of last L digits will be 4 + 5 + 6 = 15
Average = (3 + 15) / (2 + 3) = 18 / 5 = 3
Input: N = 456966, K = 1, L = 1
Approach: If the count of digits in n is less than (K + L) then it isn’t possible to find the average without digits overlapping and print -1 in that case. If that’s not the case, find the sum of the last L digits of N and store it in a variable say sum1 then find the sum of the first K digits of N and store it in sum2. Now, print the average as (sum1 + sum2) / (K + L).
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find smallest number with given number of digits and sum of digits under given constraints
- Find the Largest number with given number of digits and sum of digits
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Check if the sum of digits of number is divisible by all of its digits
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Sum of the digits of square of the given number which has only 1's as its digits
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Given a number n, find the first k digits of n^n
- Find first and last digits of a number
- Find next greater number with same set of digits
- Find the number of integers from 1 to n which contains digits 0's and 1's only
- Find N digits number which is divisible by D
- Find the total Number of Digits in (N!)N
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.