Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
¿Qué tiene de malo mi solución? (ejercicio de clasificación de hackers: operación bit a bit)

el enlace para el tamaño del ejercicio En resumen, 'n' es una serie de números del 1 al n, y 'k' es un número. Necesito devolver el mayor resultado de a&b (a<b) siempre que sea menor que k, por ejemplo 1&2, 1&3…2&3,2&4…

Obtengo 0 cada vez que ejecuto esta función:

 function getMaxLessThanK(n, k) { let maxPV = 0; for (let a = 1; a < n; a++) { for (let b = a + 1; b <= n; b++) { if (a & b < k && a & b > maxPV) { maxPV = (a & b) } } } return maxPV }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Es un problema de precedencia de operadores .

Los operadores de comparación ( < , > , ...) tienen mayor precedencia que AND bit a bit ( & ), por lo que debe usar paréntesis para agrupar:

 if ((a & b) < k && (a & b) > maxPV) { // ... }

Fragmento completo:

 function getMaxLessThanK(n, k) { let maxPV = 0; for (let a = 1; a < n; a++) { for (let b = a + 1; b <= n; b++) { if ((a & b) < k && (a & b) > maxPV) { maxPV = (a & b); } } } return maxPV; } console.log(getMaxLessThanK(8, 5));

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!