Find the K-Beauty of a Number

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.

Example 1
Inputnum = 240, k = 2
Output2
The substrings of length 2 are "24" and "40", and both 24 and 40 divide 240.
Example 2
Inputnum = 430043, k = 2
Output2
The substrings of length 2 are "43", "30", "00", "04", and "43", and only the two occurrences of 43 divide 430043.

Constraints

  • 1 <= num <= 10^9
  • 1 <= k <= num.length (taking num as a string)

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate