Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda