Count of days remaining for the next day with higher temperature | C # program for the above approach ; 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 ; Driver Code ; Given temperatures ; Function call
using System ; using System . Collections . Generic ; class GFG { static void dailyTemperatures ( int [ ] T ) { int n = T . Length ; int [ ] daysOfWait = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) daysOfWait [ i ] = - 1 ; Stack < int > s = new Stack < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( s . Count != 0 && T [ s . Peek ( ) ] < T [ i ] ) { daysOfWait [ s . Peek ( ) ] = i - s . Peek ( ) ; s . Pop ( ) ; } s . Push ( i ) ; } for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( daysOfWait [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 73 , 74 , 75 , 71 , 69 , 72 , 76 , 73 } ; dailyTemperatures ( arr ) ; } }