π§ Difficulty: Hard
π‘ Topic: Palindromes, Permutations, Counting, Math, Combinatorics
π₯ From: Coding Moves - YouTube Channel
You are given two positive integers n and k.
An integer x is called k-palindromic if:
xis a palindrome.xis divisible byk.
An integer is called good if its digits can be rearranged to form a k-palindromic integer.
Return the count of all good integers with exactly n digits and no leading zero.
1 <= n <= 101 <= k <= 9
- Generate all
n-digit palindromes using half-construction. - Filter the ones divisible by
k(i.e., k-palindromes). - For each unique digit multiset of those palindromes:
- Count how many permutations of those digits are valid
n-digit numbers (no leading zero).
- Count how many permutations of those digits are valid
- Use factorial math for efficient permutation counting.
python solution.py