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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:41:23+00:00 2026-05-11T17:41:23+00:00

You are given 2^32-2 unique numbers that range from 1 to 2^32-1. It’s impossible

  • 0

You are given 2^32-2 unique numbers that range from 1 to 2^32-1. It’s impossible to fit all the numbers into memory (thus sorting is not an option). You are asked to find the missing number. What would be the best approach to this problem?


Let’s assume you cannot use big-integers and are confined to 32bit ints.

ints are passed in through standard in.

  • 1 1 Answer
  • 1 View
  • 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-05-11T17:41:24+00:00Added an answer on May 11, 2026 at 5:41 pm

    Major Edit: Trust me to make things much harder than they have to be.

    XOR all of them.

    I’m assuming here that the numbers are 1 to 232 – 1 inclusive. This should use 1 extra memory location of 32 bits.

    EDIT: I thought I could get away with magic. Ah well.

    Explanation:

    For those who know how Hamming Codes work, it’s the same idea.

    Basically, for all numbers from 0 to 2n – 1, there are exactly 2(n – 1) 1s in each bit position of the number. Therefore xoring all those numbers should actually give 0. However, since one number is missing, that particular column will give one, because there’s an odd number of ones in that bit position.

    Note: Although I personally prefer the ** operator for exponentiation, I’ve changed mine to ^ because that’s what the OP has used. Don’t confuse ^ for xor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following list of descending unique numbers (3,2,1) I wish to generate all
What is an efficient way of generating N unique numbers within a given range
Given a table action(start:DATE, length:NUMBER, type:NUMBER), with all records unique, I need to select
Let's say I want to find all sets of 5 single-digit, non-repeating numbers that
I'd like to implement a system that generates unique NxN blocks when given a
I'm writing an import utility that is using phone numbers as a unique key
i want to generate a sequence of unique random numbers in the range of
Given a list I need to return a list of lists of unique items.
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
I give possibility to user to input strings with unique keys that represent one-line

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.