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 8478423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:44:31+00:00 2026-06-10T18:44:31+00:00

I am looking for a standard container/library in C++ with following functionalities: Storing the

  • 0

I am looking for a standard container/library in C++ with following functionalities:

  1. Storing the windows of numbers (enqueue and dequeue are enough).
  2. Returning the number of unique numbers in the window.

It can be something merging std::queue and std::set capabilities.

EDITED:
Example expected operation. For this sequence ‘1 2 3 3 4 4 5 5 6 6 7 7 8’ and window size of 2 we would have following steps:

  1. Window = [1 2], unique ones = 2
  2. Window = [2 3], unique ones = 2
  3. Window = [3 3], unique ones = 1
  4. Window = [3 4], unique ones = 2
  5. and so on …
  • 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-10T18:44:33+00:00Added an answer on June 10, 2026 at 6:44 pm

    You want two containers:

    • a deque<number> to store the numbers in the window in order;
    • a map<number, size_t> (or unordered_map if available) to store the count of each unique number.

    Then your operations are:

    void push(number n) {
        deque.push_back(n);
        ++map[n];
    }
    
    void pop() {
        auto found = map.find(deque.front());
        assert(found != map.end());
        assert(found->second > 0);
        if (--found->second == 0) {
            map.erase(found);
        }
        deque.pop_front();
    }
    
    size_t count_unique() {
        return map.size();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a high-end graphics library for Java Standard Edition. I know
I'm looking for standard container (if any exists) that will have constant time for:
I was fishing around in D's standard library looking for a Set implementation, and
I'm trying to learn android system and was looking into standard (default) DescClock application
I'm looking for a standard dual-map structure - is there one implemented in std/boost/another
I'm looking for a standard markup language to transmit addresses (locations). I really need
I am looking for the most standard way to achieve modal dialogs in ASP.NET
I'm looking to implement SQL Server Reporting Services as our standard reporting platform in
I'm looking for the source code of Sun's standard java compiler, javac . jdk1.6.0_07
Looking at the DateTimeFormatInfo documentation, it appears that all the standard formats have colons

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.