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:
- 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
- Print digit's position to be removed to make a number divisible by 6
- Convert a number of length N such that it contains any one digit at least 'K' times
- 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
- Append two elements to make the array satisfy the given condition
- Minimum number of given operations required to make two strings equal
- Count the number of subsequences of length k having equal LCM and HCF
- Element equal to the sum of all the remaining elements
- Number of non-decreasing sub-arrays of length greater than or equal to K
- Minimum number of cuts required to make circle segments equal sized
- Find the minimum number of preprocess moves required to make two strings equal
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.