Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
HackerRank Seperate the Numbers Challenge

Hello everyone; I have been grappling with 3 cases that are not passing. The difference is so subtle with a digit change. I tried JavaScript notations for very large numbers or scientific notations but of of no avail. The challenge is linked here.

The different test cases are here.

console.log(separateNumbers("90071992547409929007199254740993")) //Gives NO although it should give "yes"

console.log(separateNumbers("90071992547401929007199254740193")) //Gives YES when 9 replaced with 1//

My code goes like:

function separateNumbers(s) {
var beautiful = true;
for (let len = 1; len < s.length; len++) { 
    var first = s.substr(0, len);
    var num = s.substr(0, len);
    if (s.length <= len) {
        continue;
    }
    var sNew = ''.concat(first.toString());
    while (sNew.length < s.length) {
        num++;
        sNew = sNew.concat(num.toString());
    }
    if (sNew === s) {
        console.log('YES ' + first);
        beautiful = false;
        continue;
    }
}
if (beautiful) {
    console.log('NO')
}

}

Your helps are very much appreciated. Thanks many

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There is no issue with your algorithm, it is working exactly as expected (and is right, btw).

The issue is with JS-Number data-type. The MAX_SAFE_INTEGER constant has a value of 9007199254740991. The reasoning behind that number is that JavaScript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent integers between -(2^53 - 1) and 2^53 - 1

Instead of using std Number type, use BIGINT. That should give you correct answer for the test case.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda