ORIGINAL CODING QUESTION
Total wait for warmer readings
For each reading, wait until the first later STRICTLY larger reading; if none exists, its wait is zero. Return the sum of all index waits.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n integer values. Print one integer as described.
Constraints
1 ≤ n ≤ 200; -100 ≤ value ≤ 100. Inputs contain exactly the stated values.
Example 1
Input
4 2 1 3 2
Output
3
Waits are 2,1,0,0; total 3.
Example 2
Input
3 3 2 1
Output
0
No reading ever gets warmer.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Equal readings are not warmer.
Hint 2
Maintain unresolved indexes in decreasing reading order.
Hint 3
A new higher reading resolves all smaller pending readings.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →