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

What is an efficient way of generating N unique numbers within a given range
I'm looking for a good algorithm that can give me the unique edges from
i want to generate a sequence of unique random numbers in the range of
GA Unique Visitors data isn't making sense to me. From the GA FAQ we
The ids in RDBMS's are usually simple integers that go from 0 to whatever
How to generate a random (but unique and sorted) list of a fixed given
Given an integer I would like to produce a unique floating point number in
I'm plugging Django into an existing system. I have been given a legacy schema,
I would like to give a class a unique ID every time a new
Given a specific DateTime value, how do I display relative time, like: 2 hours

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.