The Find the Largest Palindrome Divisible by K interview question is a difficult number theory and string construction problem. You are given an integer (the length of the palindrome) and an integer . You need to find the largest -digit palindrome that is divisible by . Because can be large (), you must return the answer as a string.
Amazon and Google ask the Find the Largest Palindrome coding problem to test a candidate's mastery of Greedy algorithms and Dynamic Programming. Since you want the largest number, you should try to put '9's at the most significant positions. However, the divisibility rule for (especially for or ) requires a structured approach.
This problem is solved using Greedy Construction with DP/Math.
dp(index, current_remainder) stores whether it's possible to complete a palindrome starting from index with a given remainder..
For large-number divisibility, learn how to calculate the remainder of iteratively. This allows you to update the total remainder digit-by-digit without ever storing the full number. This is a powerful Number Theory interview pattern.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Smallest Divisible Digit Product II | Hard | Solve | |
| Count the Number of Powerful Integers | Hard | Solve | |
| Count of Integers | Hard | Solve | |
| Number of Ways to Divide a Long Corridor | Hard | Solve | |
| Most Expensive Item That Can Not Be Bought | Medium | Solve |