Skip to content

Muawiya-contact/-LeetCode-3272---Count-of-Good-Integers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ LeetCode 3272 - Count of Good Integers

πŸ”§ Difficulty: Hard
πŸ’‘ Topic: Palindromes, Permutations, Counting, Math, Combinatorics
πŸŽ₯ From: Coding Moves - YouTube Channel


🧠 Problem Summary

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.

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.


πŸ§ͺ Examples

Example 1:

Input: n = 3, k = 5

Output: 27


🧩 Key Constraints

  • 1 <= n <= 10
  • 1 <= k <= 9

πŸ§‘β€πŸ’» Solution Strategy

  1. Generate all n-digit palindromes using half-construction.
  2. Filter the ones divisible by k (i.e., k-palindromes).
  3. For each unique digit multiset of those palindromes:
    • Count how many permutations of those digits are valid n-digit numbers (no leading zero).
  4. Use factorial math for efficient permutation counting.

  • πŸ“¦ How to Run

python solution.py

🎬 Follow Us

πŸ“Ί Coding Moves

πŸŽ“ Helping You Move Smart in Code

πŸ”— YouTube.com/@Coding_Moves

About

# πŸš€ LeetCode 3272 - Count of Good Integers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages