Count of days remaining for the next day with higher temperature | Function to determine how many days required to wait for the next warmer temperature ; To store the answer ; Traverse all the temperatures ; Check if current index is the next warmer temperature of any previous indexes ; Pop the element ; Push the current index ; Print waiting days ; Given temperatures ; Function call
def dailyTemperatures ( T ) : NEW_LINE INDENT n = len ( T ) NEW_LINE daysOfWait = [ - 1 ] * n NEW_LINE s = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT while ( len ( s ) != 0 and T [ s [ - 1 ] ] < T [ i ] ) : NEW_LINE INDENT daysOfWait [ s [ - 1 ] ] = i - s [ - 1 ] NEW_LINE s . pop ( - 1 ) NEW_LINE DEDENT s . append ( i ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT print ( daysOfWait [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 73 , 74 , 75 , 71 , 69 , 72 , 76 , 73 ] NEW_LINE dailyTemperatures ( arr ) NEW_LINE