Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:26:15+00:00 2026-06-10T14:26:15+00:00

I want to create such class: public TrackMaxMin(int periodInSec) // use current system time

  • 0

I want to create such class:

public TrackMaxMin(int periodInSec)

// use current system time as time
public Add(decimal value)

// return maximum Value for the last periodInSec
public Max { get {} }

// return minimum Value for the last periodInSec
public Min { get {} }

I think I can use FIFO query to store Pair<DateTime, decimal> and on each Add call I should:

  • remove “outdated” values from query. when removing “update” cached Max/Min if needed
  • add new value. update Max/Min if needed

My solution is trivial and straightforward. Probably you can suggest something better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:26:16+00:00Added an answer on June 10, 2026 at 2:26 pm

    You can use a max-heap called max, a min-heap called min, and a queue called q.

    Let x be an element with the properties x.time and x.val.

    When Add is called:

    • Create a new element x.
    • Add x to all of the data structures.

    The running time of Add is O(lgn).

    When Max is called:

    • max.GetMax()

    The running time of Max is O(1).

    When Min is called:

    • min.GetMin()

    The running time of Min is O(1).

    For the maintenance of the model do this:

    Have only one timer that is fired each time the period of the next to go out element in q is due.

    When the period of x is due then:

    • q.Dequeue(), max.Delete(x), min.Delete(x)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a function such that each time the function runs, the
I want to use URL such as /Image/sample.png I create route, but it does
I want to create interface in cpp such that is any class implement that
I am trying to create a class as such: class CLASS { public: //stuff
I have such class in c#: public class Foo { public static readonly int
I want to create such layout: +-----------container-----------+ | +-----fixed-height-div-------+| | +-------fixed-height-div-----+| | +-fill-height-scrollable-div-+| | +-fixed-height-bottom-div-+| +---------end-container-------+ The problem
I have a pdf file on my server. I want to create such link
I want to create a route such as get '/referrals/send_invite/:email_address' I will be calling
I want to create a onscreen keyboard such that when a text field gets
I want to create a layout in such a way that on top edittext

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.