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

151
Vistas
How can i reduce the time complexity of an algorithm?

How can I reduce the complexity of an algorithm? I'm currently doing hackerrank, where I made a solution for climbing the leaderboard, but two tests are failing because of the time limit.

I'm trying to learn how to refactor my code, with less time complexity, but I have no idea how I could reduce the two for loops into one, because I have to iterate through both of the arrays to check if the player score is higher or equal to the ranked leaderboard.

The description of the task: https://www.hackerrank.com/challenges/climbing-the-leaderboard/

I could search a solution for this, but I want to learn how can I reduce time complexity in codes that I write, what my thinking should look like when I try to do this?

function climbingLeaderboard(ranked, player) {
    let positions = [];
    let temp = new Set(...[ranked]);
    ranked = Array.from(temp);
    for(let i = 0; i < player.length; i++) {
        for(let j = 0; j < ranked.length; j++) {
            if(player[i] > ranked[j] || player[i] === ranked[j]) {
                positions.push(j+1);
                break;
            } else if(j === ranked.length-1) {
                positions.push(j+2);
                break;
            }
        }
    }
    return positions;
}
about 4 years ago · Juan Pablo Isaza
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