Le migliori 150 intervisteFacile

Temperature giornaliere

Guida dettagliata e implementazione Python per il problema delle "Temperature giornaliere".

Dichiarazione del problema

Facile

Dato un array di numeri interi temperatures rappresenta le temperature giornaliere, restituisci un array answer tale che answer[i] sia il numero di giorni che devi attendere dopo il iesimo giorno per ottenere una temperatura più calda. Se non esiste un giorno futuro per cui ciò sia possibile, mantieni invece answer[i] == 0.

Scrivi una funzione dailyTemperatures(temperatures: List[int]) -> List[int].

Vincoli
  • 1 <= len(temperatures) <= 10^5
  • 30 <= temperatures[i] <= 100

Esempi

Example 1
Input
temperatures = [73, 74, 75, 71, 69, 72, 76, 73]
Output
[1, 1, 4, 2, 1, 1, 0, 0]
Explanation

Day 0 (73): next warmer is day 1 (74), wait 1 day. Day 2 (75): next warmer is day 6 (76), wait 4 days. Days 6 and 7 have no warmer future day.

Example 2
Input
temperatures = [30, 40, 50, 60]
Output
[1, 1, 1, 0]
Explanation

Each day except the last has a warmer day immediately after.

Example 3
Input
temperatures = [30, 60, 90]
Output
[1, 1, 0]
Explanation

Temperatures are strictly increasing except the last day.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche dello stack come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Apri nell'editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.