Given a number N, we have to find the minimum number of palindromes required to express N as a sum of them.
Input : N = 11
Output : 1
Explanation: 11 is itself a palindrome.
Input : N = 65
Output : 3
Explanation: 65 can be expressed as a sum of three palindromes (55, 9, 1).
In the previous post, we discussed a dynamic programming approach to this problem which had a time and space complexity of O(N3/2).
Cilleruelo, Luca, and Baxter proved in a 2016 research paper that every number can be expressed as the sum of maximum three palindromes in any base b >= 5 (this lower bound was later improved to 3). For the proof of this theorem, please refer to the original paper. We can make the use of this theorem by safely assuming the answer to be three if the number N is not itself a palindrome and cannot be expressed as the sum of two palindromes.
Below is the implementation of the above approach:
Time Complexity: O(√(N)log N).
- Minimum number of palindromes required to express N as a sum | Set 1
- Minimum number of given powers of 2 required to represent a number
- Minimum number of given operation required to convert n to m
- Minimum number of changes required to make the given array an AP
- Minimum number operations required to convert n to m | Set-2
- Minimum number of operations required to reduce N to 1
- Minimum number of operations required to sum to binary string S
- Minimum number of bottles required to fill K glasses
- Minimum number of given moves required to make N divisible by 25
- Minimum number of integers required to fill the NxM grid
- Minimum number of mails required to distribute all the questions
- Minimum number of cuts required to pay salary from N length Gold Bar
- Minimum number of given operations required to make two strings equal
- Find out the minimum number of coins required to pay total amount
- Minimum splits required to convert a number into prime segments
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.