#3260
Find the Largest Palindrome Divisible by K
hard · 16.9% accepted · 108 likes · top 1%
math · string · dynamic programming · greedy · number theory
Description
You are given two positive integers n and k.
An integer x is called k-palindromic if:
- x is a palindrome.
- x is divisible by k.
Return the largest integer having n digits (as a string) that is k-palindromic.
Note that the integer must not have leading zeros.
Solution