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:
1
💡 Note:
Substrings: "43", "30". 430 ÷ 43 = 10 (exact division), but 430 ÷ 30 = 14.333... (not exact). Only "43" divides evenly, so k-beauty is 1.
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code