DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Separate the Numbers

function separateNumbers(s) {
  let subString = "";
  let isValid = false;
  if (s.length === 1) {
    console.log("NO");
  } else {
    for (let i = 1; i <= s.length / 2; i++) {
      subString = s.substring(0, i);
      let num = BigInt(subString);
      let validString = subString;
      while (validString.length < s.length) {
        validString +=BigInt(++num);
      }
      if (s === validString) {
        isValid = true;
        break;
      }
    }

    if (!isValid) {
      console.log("NO");
    } else {
      console.log("YES", subString);
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)