Partition given string in such manner that i’th substring is sum of (i-1)’th and (i-2)’nd substring.
Input : "11235813" Output : ["1", "1", "2", "3", "5", "8", "13"] Input : "1111223" Output : ["1", "11", "12", "23"] Input : "1111213" Output : ["11", "1", "12", "13"] Input : "11121114" Output : 
1. Iterate through the given string by picking 3 numbers (first, seconds and third) at a time starting from one digit each.
2. If first + second = third, recursively call check() with second as first and third as second. The third is picked based on next possible number of digits. (The result of addition of two numbers can have a max. of second’s & third’s digits + 1)
3. Else, first increment the third (by adding more digits) till the limit (Here limit is sum of first and second).
4. After incrementing third, following cases arise.
a) When doesn’t match, increment the second offset.
b) When doesn’t match, increment the first offset.
c) Note: Once a call to check() is made after incrementing the third offset, do not alter the second or first, as those are already finalized.
5. When the end of the string is reached and the condition is satisfied, add “second” and “third” to the empty list. While rolling back the recursive stack, prepend the “first” to the list so the order is preserved.
true [1, 1, 2, 3, 5, 8, 13]
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
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Minimum length of substring whose rotation generates a palindromic substring
- Find length of longest subsequence of one string which is substring of another string
- Check if a string is substring of another
- Frequency of a substring in a string
- Queries to check if string B exists as substring in string A
- Minimum changes required to make first string substring of second string
- Lexicographical Maximum substring of string
- First substring whose reverse is a word in the string
- Shortest substring of a string containing all given words
- Frequency of a substring in a string using pthread
- Convert to a string that is repetition of a substring of k length
- Python | Check if a Substring is Present in a Given String
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 : Srinivas Kothuri