java.lang.Object
g3201_3300.s3260_find_the_largest_palindrome_divisible_by_k.Solution

public class Solution extends java.lang.Object
3260 - Find the Largest Palindrome Divisible by K.

Hard

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.

Example 1:

Input: n = 3, k = 5

Output: “595”

Explanation:

595 is the largest k-palindromic integer with 3 digits.

Example 2:

Input: n = 1, k = 4

Output: “8”

Explanation:

4 and 8 are the only k-palindromic integers with 1 digit.

Example 3:

Input: n = 5, k = 6

Output: “89898”

Constraints:

  • 1 <= n <= 105
  • 1 <= k <= 9
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    java.lang.String
    largestPalindrome(int n, int k)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • largestPalindrome

      public java.lang.String largestPalindrome(int n, int k)