
Introduction
Array is a popular data structure and one of the first data structures that are learned while beginning to learn data structures or any programming language. A wide number of questions are also asked on arrays in technical interviews of top tech companies. A mastery over arrays could help open doors to a lot of new ideas for approaching a programming problem and solving it. In this article, we are going to take a look at one such problem.
Problem Statement
In a given integer array of everyday temperatures, the task is to find the number of days remaining for the next day with a warmer temperature. If there is no day in the future for which warmer temperature is possible, print -1.
This blog will explore the various approaches to solve such problems and discuss each approach's time and space complexities.
Examples
Eg. 1- Input: temperatures = [30,60,90]
Output:
1,1,-1
After 30, the following warmer temperature is 60, at a distance of 1
After 60, the next warmer temperature is 90, at a distance of 1
After 90, there is no warmer temperature further
Eg. 2- Input: arr[] = {78, 75, 74, 72}
Output:
-1, -1, -1, -1
The given array is in descending order, so:
After 78, there is no warmer temperature further
After 75, there is no warmer temperature further
After 74, there is no warmer temperature further
After 72, there is no warmer temperature further
Eg. 3- Input: arr[]:

Output:
6, 2, 1, 3, 1, 1, -1, -1 |
After 75, the following warmer temperature is 76, at a distance of 6
After 73, the next warmer temperature is 74, at a distance of 2
After 71, the next warmer temperature is 74, at a distance of 1
After 74, the next warmer temperature is 76, at a distance of 3
After 69, the following warmer temperature is 72, at a distance of 1
After 72, the next warmer temperature is 76, at a distance of 1
After 76, there is no warmer temperature further
After 73, there is no warmer temperature further