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

  • Home
  • SEARCH
  • 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 8992061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:52:07+00:00 2026-06-15T22:52:07+00:00

Possible Duplicate: Easy interview question got harder: given numbers 1..100, find the missing number(s)

  • 0

Possible Duplicate:
Easy interview question got harder: given numbers 1..100, find the missing number(s)

A job interview question.
Suppose we have an array of size N-2, with all the values from 1 to N, except for two missing values. (N>0)

An algorithm for finding the two missing numbers is needed, that traverses the array only once.

  • 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-15T22:52:08+00:00Added an answer on June 15, 2026 at 10:52 pm
    // Receiving array with values from 1 to N (NOT 0 to N-1)
    // N is max value & # of values, NOT size of arr (arr is in size N-2)
    void Find2Numbers(unsigned arr[], size_t N, unsigned & n1, unsigned & n2)
    {
        unsigned sum = N*(N+1)/2;  // sum of elements
        double pro = 1;  // Products will be calculated within the loop, because fact(N) can be very large
    
        for(size_t i = 0 ; i < N-2 ; i++)
        {
            pro *= (i+1);  // mult by i+1 to get factorial
            pro /= arr[i];  // divide by arr[i] to find n1*n2
            sum -= arr[i];
        }
        pro *= (N-1)*N;  // 2 missing indexes, as arr is missing 2 elements
        // sum = n1+n2
        // pro = n1*n2  =>
        n1 = (sum+sqrt(sum*sum-4*pro))/2;
        n2 = (sum-sqrt(sum*sum-4*pro))/2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Easy interview question got harder: given numbers 1..100, find the missing number(s)
Possible Duplicate: Easy interview question got harder: given numbers 1..100, find the missing number(s)
Possible Duplicate: Is there an easy way to return a string repeated X number
Possible Duplicate: Is there an easy way to return a string repeated X number
Possible Duplicate: Is there an easy way to convert a number to a word
Possible Duplicate: Create shortcut to console.log() In javascript we can easy assign functions to
Possible Duplicate: Is there an easy way in .NET to get “st”, “nd”, “rd”
Possible Duplicate: Try to describe polymorphism as easy as you can What is polymorphism?
Possible Duplicate: PHP MVC - Convert JSON to Model data Is there an easy
Possible Duplicate: What's the best place to find Git reference content online while kernel.org

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.