Given a string str in which an integer is appended in the end (with or without leading zeroes). The task is to find a single digit from the range [0, 9] that must be appended in the end of the integer so that the number becomes equal to the length of remaining string. Print -1 if its not possible.
Input: str = “geeksforgeeks1”
Length of “geeksforgeeks” is 13
So, 3 must be appended at the end of 1.
Input: str = “abcd0”
Approach: Find the number appended in the end of the string say num and append a 0 in the end which is the least digit possible i.e. num = num * 10. Now find the length of the remaining string ignoring the numeric from the end say len. Now the digit which must be appended will be digit = len – num. If digit is in the range [0, 9] then print it else print -1.
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
- Minimum number of swaps to make two binary string equal
- Check length of a string is equal to the number appended at its last
- Count of Numbers in Range where first digit is equal to last digit of the number
- Number of ways to remove a sub-string from S such that all remaining characters are same
- Convert a number of length N such that it contains any one digit at least 'K' times
- Print digit's position to be removed to make a number divisible by 6
- Minimum swaps to make two strings equal by swapping only with third string
- Minimum length String with Sum of the alphabetical values of the characters equal to N
- Number of character corrections in the given strings to make them equal
- Element equal to the sum of all the remaining elements
- Append two elements to make the array satisfy the given condition
- Minimum number of operations required to make two strings equal
- Minimum number of given operations required to make two strings equal
- Count the number of subsequences of length k having equal LCM and HCF
- Count of pairs (A, B) in range 1 to N such that last digit of A is equal to the first digit of B
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.