PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Sonatus

Compute days until a higher reading

Last updated: May 27, 2026

Quick Overview

This question evaluates proficiency in array processing and the next-greater-element concept, measuring algorithmic reasoning about sequence traversal, comparisons, and managing time/space trade-offs.

  • hard
  • Sonatus
  • Coding & Algorithms
  • Software Engineer

Compute days until a higher reading

Company: Sonatus

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given an array `readings[]` representing sensor values over consecutive days (e.g., temperatures). For each day `i`, compute how many days you must wait until you see a strictly higher reading on a future day `j > i`. If there is no future day with a higher reading, output `0` for that day. ### Input - An integer array `readings` of length `n`. ### Output - An integer array `ans` of length `n` where `ans[i]` is the number of days until a higher reading occurs, or `0` if none exists. ### Example - Input: `readings = [30, 38, 30, 36, 35, 40, 28]` - Output: `[1, 4, 1, 2, 1, 0, 0]` ### Constraints (typical) - `1 <= n <= 2e5` - Readings fit in 32-bit signed integers. ### Notes - “Higher” means strictly greater (`>`), not greater-or-equal.

Quick Answer: This question evaluates proficiency in array processing and the next-greater-element concept, measuring algorithmic reasoning about sequence traversal, comparisons, and managing time/space trade-offs.

Sonatus logo
Sonatus
Feb 12, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0

You are given an array readings[] representing sensor values over consecutive days (e.g., temperatures).

For each day i, compute how many days you must wait until you see a strictly higher reading on a future day j > i. If there is no future day with a higher reading, output 0 for that day.

Input

  • An integer array readings of length n .

Output

  • An integer array ans of length n where ans[i] is the number of days until a higher reading occurs, or 0 if none exists.

Example

  • Input: readings = [30, 38, 30, 36, 35, 40, 28]
  • Output: [1, 4, 1, 2, 1, 0, 0]

Constraints (typical)

  • 1 <= n <= 2e5
  • Readings fit in 32-bit signed integers.

Notes

  • “Higher” means strictly greater ( > ), not greater-or-equal.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Sonatus•More Software Engineer•Sonatus Software Engineer•Sonatus Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.