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

120
Views
Complejidad temporal de la pregunta de pila monotónica

Según tengo entendido, la complejidad de tiempo de este código es O(N). El bucle for iterará solo una vez, por lo que la complejidad de tiempo representa O(N), pero hay un bucle while dentro del bucle for.

Así que hay un bucle while anidado dentro del bucle for. ¿Por qué estamos ignorando la complejidad temporal de eso?

 var dailyTemperatures = function(temperatures) { let result = new Array(temperatures.length).fill(0); let stack = []; for(let i = 0; i < temperatures.length; i++) { while(stack.length > 0 && temperatures[i] > temperatures[stack[stack.length - 1]]) { let index = stack.pop(); console.log('hello'); result[index] = i - index; } stack.push(i); } return result; };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Porque while loop simplemente está sacando elementos de la pila uno por uno y no puede haber más de N elementos empujados dentro de la pila (cada elemento empujado una vez). Entonces, aunque el bucle esté anidado dentro del bucle for, no se ejecutará más de N veces.

about 4 years ago · Juan Pablo Isaza 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!