Instead of storing values on the stack, store indices. When you pop index because temperature at index is higher: answer[] = You get the number of days between and the next warmer day at . The stack comparison uses , but you push and pop indices.
Data Structures19 sections · 729 units
Open in CourseDaily Temperatures - The Idea
Store indices