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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:43:08+00:00 2026-05-30T10:43:08+00:00

If we have an array of integers then how can we find the number

  • 0

If we have an array of integers then how can we find the number of ways that they be XORed so that the result is 0 . Here at each step only one integer(i) can be decreased by any amount say d such that (i-d)>=0 . E.g for the integers 11,15,8 we can decrease 11 to 7 so that 7^15^8 =0 . Similary 15 can be reduced to 3 such that 11^3^8 = 0 and 8 can be reduced to 4 such that 11^15^4=0 . Hence total ways is 3

My approach: to this is for each integer , go on decreasing it and at each step XOR it with remaining integers in the array , if the result is 0 , break. Check this for all integers and get the total ways. But this is 0(n^2) . Is there any efficient way to do it?
Thanks.

  • 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-30T10:43:10+00:00Added an answer on May 30, 2026 at 10:43 am

    You can XOR all integers in your array, then in loop XOR the result with each of your integers (it will “remove” that integer from all because x^x is always 0). As a result you’ll get XOR of the other members and that’s the number to be replaced (because x^x is always 0).

        int[] a = new int [size];
        //initialize 'a' array
        int[] b = new int [size];
        int all = 0;
        for(int i = 0; i<a.length; i++)
            all=all^a[i];
    
        for(int i =0; i< size; i++)
            b[i] = all^a[i];
    

    In b[i] you’ll get the number to be replaced with a[i] to get zero.
    I edited my answer and tried, it works. This is O(n).

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

Sidebar

Related Questions

Each of my user's have a set number of slots for storage. They can
Possible Duplicate: I have an array of integers, how do I use each one
Given an array of prime factors of a natural number, how can I find
I have an array of 10 integers, and k is an integer that loops
Assume that we have an array of integers (3x3) depicted as follows: +-+-+-+ |
I am experimenting with OpenSSL for Delphi a unit that you can find here
If we have an array of integers, then is there any efficient way other
I have an array of Integers in Java, I would like use only a
I have an array of integers in my core data model. It is set
I have an array of integers which represent a RGB image and would like

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.