<p>Given an array of integers <code>temperatures</code> represents the daily temperatures, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is the number of days you have to wait after the</em> <code>i<sup>th</sup></code> <em>day to get a warmer temperature</em>. If there is no future day for which this is possible, keep <code>answer[i] == 0</code> instead.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> temperatures = [73,74,75,71,69,72,76,73]
<strong>Output:</strong> [1,1,4,2,1,1,0,0]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> temperatures = [30,40,50,60]
<strong>Output:</strong> [1,1,1,0]
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> temperatures = [30,60,90]
<strong>Output:</strong> [1,1,0]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;=&nbsp;temperatures.length &lt;= 10<sup>5</sup></code></li>
	<li><code>30 &lt;=&nbsp;temperatures[i] &lt;= 100</code></li>
</ul>

class Solution:
    def dailyTemperatures(self, temperatures: List[int]) -> List[int]: 

        from collections import defaultdict

        res = [] 
        dt_temp = defaultdict( int)

  

        curr_max = -1
        # prev_temp_list

        for temp_ind in  range(len(temperatures)-1, -1, -1):  # O n
            temp_curr = temperatures[temp_ind]

            # if temp_curr not in dt_temp:
                # prev_temp_list.append(temp_current
            dt_temp[temp_curr] = temp_ind 

            curr_max = max(temp_curr,  curr_max)
            curr_res = 1000000

            if curr_max > temp_curr:
                # find the index of nearest number
                for i in range(temp_curr+1, curr_max+1):
                    if i in dt_temp:
                        curr_res = min(curr_res,  dt_temp[i] - temp_ind)
                        if curr_res == 1:
                            break
                res.append(curr_res)
            else:
                res.append(0) 

        return res[-1::-1]
            





29800