Find the K-Beauty of a Number - Problem
The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions:
- It has a length of
k. - It is a divisor of
num.
Given integers num and k, return the k-beauty of num.
Note:
- Leading zeros are allowed.
- 0 is not a divisor of any value.
A substring is a contiguous sequence of characters in a string.
Input & Output
Example 1 — Basic Case
$
Input:
num = 240, k = 2
›
Output:
2
💡 Note:
Substrings of length 2: "24" and "40". Both 24 and 40 divide 240 evenly, so k-beauty is 2.
Example 2 — With Leading Zero
$
Input:
num = 430, k = 2
›
Output:
2
💡 Note:
Substrings: "43", "30". 430 ÷ 43 = 10 and 430 ÷ 30 = 14.33... Only "43" divides evenly, but "30" also works: 430 ÷ 30 = 14.33 (not integer). Actually 43 divides 430, and 30 doesn't divide 430 evenly.
Example 3 — No Valid Divisors
$
Input:
num = 123, k = 3
›
Output:
1
💡 Note:
Only substring is "123". Since 123 ÷ 123 = 1, it divides itself, so k-beauty is 1.
Constraints
- 1 ≤ num ≤ 109
- 1 ≤ k ≤ num.length
Visualization
Tap to expand
Understanding the Visualization
1
Input
Number 240 with k=2
2
Extract Substrings
Get all 2-length substrings: "24", "40"
3
Count Divisors
Count how many substrings divide the original number
Key Takeaway
🎯 Key Insight: Convert to string, slide window of size k, and count valid divisors
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code