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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:32:58+00:00 2026-05-11T09:32:58+00:00

Suppose you have a sorted range (x to y) of values in an array.

  • 0

Suppose you have a sorted range (x to y) of values in an array.

x = 3; y = 11;  array == 3, 4, 5, 6, 7, 8, 9, 10, 11 

But it is possible that some values are duplicated and some are missing, so you might have:

array == 4, 5, 5, 5, 7, 8, 9, 10, 10 

What’s the best way in your language to find all duplicates and missing values so you get:

resultMissingValuesArray == 3, 6, 11 resultDuplicatesArray == 5, 5, 10 

Here’s some C++ code to get you started:

#include <vector> #include <iostream> #include <algorithm>  using namespace std;  const int kLastNumber = 50000; // last number expected in array const int kFirstNumber = 3; // first number expected in array  int main() {     vector<int> myVector;      // fill up vector, skip values at the beginning and end to check edge cases     for(int x = kFirstNumber + 5; x < kLastNumber - 5; x++)     {            if(x % 12 != 0 &&  x % 13 != 0 && x % 17 != 0)             myVector.push_back(x);  // skip some values          else if(x % 9 == 0)         {             myVector.push_back(x);  // add duplicates             myVector.push_back(x);           }          else if(x % 16 == 0)         {             myVector.push_back(x);  // add multiple duplicates             myVector.push_back(x);               myVector.push_back(x);               myVector.push_back(x);           }     }      // put the results in here     vector<int> missingValues;     vector<int> duplicates;      //  YOUR CODE GOES HERE               // validate missingValues for false positives     for(int x = 0; x < (int) missingValues.size(); ++x)     {         if(binary_search(myVector.begin(), myVector.end(), missingValues.at(x)))             cout << 'Oh noes! You missed an unmissed value. Something went horribly, horribly wrong.';     }      // validate duplicates (I think... errr)     vector<int>::iterator vecItr = myVector.begin();     vector<int>::iterator dupItr = duplicates.begin();      while(dupItr < duplicates.end())     {         vecItr = adjacent_find(vecItr, myVector.end());               if(*vecItr != *dupItr)             cout << 'Oh noes! Something went horribly, horribly wrong.';          // oh god         while(++dupItr != duplicates.end() && *(--dupItr) == *(++dupItr) && *vecItr == *(++vecItr));                      ++vecItr;     }      return 0; } 

I didn’t test the validation parts much, so there may be be something wrong with them (especially with the duplicates one).

I will post my own solution as an answer.

  • 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. 2026-05-11T09:32:58+00:00Added an answer on May 11, 2026 at 9:32 am

    Since you’ve marked it language-agnostic, here’s the algorithm I’d use.

    # Get numbers and sort them in ascending order.  input x,y; input number[1..n]; sort number[1..n];  # Set dups and missing to empty sets.  dups = []; missing = [];  # Get edge cases.  if number[1] > x:     foreach i x .. number[1] - 1:         missing.add(i) if number[n] < y:     foreach i number[n] + 1 .. y:         missing.add(i)  # Process all numbers starting at second one.  foreach i 2 .. n:     # If number same as last and not already in dups set, add it.      if number[i] == number[i-1] and not dups.contains(number[i]):         if number[i] >= x and number[i] <= y:             dups.add(number[i])      # If number not last number plus one, add all between the two     #   to missing set.      if number[i] != number[i-1] + 1:         foreach j number[i-1] + 1 .. number[i] - 1:             if j >= x and j <= y:                 missing.add(j) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 258k
  • Answers 258k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't. You need to write some code to do… May 13, 2026 at 10:55 am
  • Editorial Team
    Editorial Team added an answer Without knowing specifics of your design, that's how the Interface… May 13, 2026 at 10:55 am
  • Editorial Team
    Editorial Team added an answer If the projects in question rely on GNU Make or… May 13, 2026 at 10:55 am

Related Questions

I have a telerik:RadGrid that is bound to a SQL Data Source. One of
I'm constructing a prototype site for my company, which has several thousand employees and
I'm working on an ASP.NET application which is supposed to output detector data for
Suppose you have a full path to an accessible file or folder on the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.