Answer: SMALLCASE Off-Campus OA (2025) | Find the Largest Palindrome Divisible by K Pro
Answer · Posted Jun 2026
Approach Since n ≤ 9, the search space is small enough to use backtracking. A palindrome is completely determined by its first half. We construct the palindrome from the outside toward the center: Place the same digit at symmetric positions. Try digits from 9 down to 1. Once the palindrome is complete, check divisibility by k. Return the first valid palindrome found because we generate candidates in descending order. Strategy Create a character array of size n. Fill symmetric positions ...
The full answer & interview discussion are available to premium members.
Log in Create a free account