DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Find the K-Beauty of a Number

Find the K-Beauty of a Number

/**
 * @param {number} num
 * @param {number} k
 * @return {number}
 */
var divisorSubstrings = function(num, k) {
  let strNum = num.toString();
  let beautyCount = 0;

  for (let i = 0; i < strNum.length; i++) {
    let divisor = strNum.substring(i, k + i);
    if (divisor.length === k && num % parseInt(divisor) === 0) {
      beautyCount++;
    }
  }
  return beautyCount;
};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)