Given a numeric string (length <= 32), split it into two or more integers( if possible), such that
1) Difference between current and previous number is 1.
2) No number contains leading zeroes
If it is possible to separate a given numeric string then print “Possible” followed by the first number of the increasing sequence, else print “Not Possible“.
Input : 1234 Output : Possible 1 Explanation: String can be split as "1", "2", "3", "4" Input : 99100 Output :Possible 99 Explanation: String can be split as "99", "100" Input : 101103 Output : Not Possible Explanation: It is not possible to split this string under given constraint.
Approach : The idea is to take a substring from index 0 to any index i (i starting from 1) of the numeric string and convert it to long data type. Add 1 to it and convert the increased number back to string. Check if the next occurring substring is equal to the increased one. If yes, then carry on the procedure else increase the value of i and repeat the steps.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Maximize count of 0s in left and 1s in right substring by splitting given Binary string
- Python Regex to extract maximum numeric value from a string
- Extract maximum numeric value from a given string | Set 2 (Regex approach)
- Split numeric, alphabetic and special symbols from a String
- Extract maximum numeric value from a given string | Set 1 (General approach)
- Minimum circular rotations to obtain a given numeric string by avoiding a set of given strings
- Mobile Numeric Keypad Problem
- Count number of substrings with numeric value greater than X
- Minimum Cost to make two Numeric Strings Identical
- Convert a sentence into its equivalent mobile numeric keypad sequence
- Count Uppercase, Lowercase, special character and numeric values
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Create a new string by alternately combining the characters of two halves of the string in reverse
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- String slicing in Python to check if a string can become empty by recursive deletion
- Transform string str1 into str2 by taking characters from string str3
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Minimal moves to form a string by adding characters or appending string itself
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.
Improved By : manishshaw1