Coding problem
Steps until a higher value
The task
A weather app shows, for each day of a forecast, how many days you must wait for a warmer day.
Complete StepsToHigher(int[] values). For each index, return how many steps forward the next strictly higher value is, or 0 if no later value is higher. The result has the same length as values.
Signature
public static int[] StepsToHigher(int[] values)
Examples
[4, 1, 2, 5]→[3, 1, 1, 0]. After 4, the first higher value is 5, three steps on.[2, 2, 3]→[2, 1, 0]. An equal value is not higher, so the first 2 waits for the 3.
Limits: Up to 300,000 values.
The tests check: an empty array, one value, rising and falling values, equal values, a dip and a rise, negative values, and 300,000 falling values in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// For each index, the number of steps to the next strictly higher value, or 0 if there is none.
public static int[] StepsToHigher(int[] values)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.