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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T10:59:33+00:00 2026-05-28T10:59:33+00:00

I was recently in an interview where they asked me technical questions. One was

  • 0

I was recently in an interview where they asked me technical questions. One was how you would calculate which number in a list of length n-1 was missing. The list contained every number from 1 to n, except i where 1 <= i <= n. The numbers were not in order. My solution was to add them all up, then subtract that from the calculation of the numbers from 1 to n, by adding 1 to n and multiplying by n/2 or (n-1)/2 as appropriate. But I got the sense that there was a better way to do it. What is the optimal solution?

  • 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-05-28T10:59:34+00:00Added an answer on May 28, 2026 at 10:59 am

    Your answer is good enough, in my opinion.

    But some people — perhaps your interviewer is one of them — are worried about overflow and such. In that case, use XOR instead of addition.

    To obtain the XOR of the integers from 0 to n, just XOR together the array indices as you loop. Given the XOR of the integers from 0 to n, and the XOR of the array elements, you just XOR the two of those together to get the missing element.

    P.S. The sum of the integers from 1 to n is always (n+1)*n/2

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

Sidebar

Related Questions

Recently i had an interview in which the question was asked as How would
Here one more basic question asked in MS interview recently class A { public
Recently I faced few interview questions.The interviewer asked the to give the detailed answer.
Recently I was asked the following questions in an interview: How will you do
I attended interview for samsung. They asked lot of questions on memory layout of
I recently attended an interview and they asked me the question Why Interfaces are
Recently in an interview I was asked several questions related to the Big-O of
Recently in a technical interview, I was asked to write a program to find
I recently gave an interview at a company where they asked me the following
This is a question I was asked at my interview recently: Which 'Random' object(s)

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.