You are viewing a single comment's thread. Return to all comments →
JS:
function separateNumbers(s) { const mid = Math.floor(s.length / 2); let len = 1; while (len <= mid){ let idx = 0; let pass = true; let isNine = false; let firstNbr = null; while (idx + len < s.length && pass === true) { const n1 = BigInt(s.substring(idx, idx + len)); if (!firstNbr) firstNbr = n1; isNine = !isNine && s.substring(idx, idx + len).split('').every(el => el === '9'); idx += len; if (isNine === true) len++; const n2 = BigInt(s.substring(idx, idx + len)); if (BigInt(n2 - n1) !== BigInt(1) || s[idx] === '0') pass = false; } if (pass) { console.log(`YES ${firstNbr}`); return; } if (!isNine) len++; } console.log('NO'); }
Seems like cookies are disabled on this browser, please enable them to open this website
Separate the Numbers
You are viewing a single comment's thread. Return to all comments →
JS: