Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 2 numbers. Find the missing numbers.



Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least o..

Answer / Kundan Kumar

One way to find the missing numbers is by using bit manipulation technique. Create a bit mask with all bits set from 0 to n-1. Perform a bitwise AND operation on the bit mask and the sum of all array elements, then perform bitwise OR operations between the result and each number from 1 to n-1 until two numbers are obtained whose XOR is zero. The two missing numbers are these two numbers. Time complexity is O(n).

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Programming Languages AllOther Interview Questions

Who is providing best mainframes online training in Hyderabad

1 Answers  


how we can call xml file in java file using Android platform?

2 Answers   TCS,


1. Consider the following input and generate the object code using single pass assembler. JOHN START 0 USING *,15 L 1,FIVE A 1,FOUR ST 1,TEMP FOUR DC F’4’ FIVE DC F’5’ TEMP DS ‘F END

1 Answers   Wipro,


what is the draw back of Power builder

0 Answers   IBM,


What is meant by spooling

2 Answers   Qiscet,


how will you do destructive read and non destructive read in data queue.....

0 Answers   CTS,


I am looking for selenium RC online Training in chennai. can any one tell me the best institute

1 Answers  


What is the Difference between in memory database and physical database

1 Answers  


how to generate dsnless connectivity in j2ee

1 Answers  


Find out the list of authorization objects which contains activity as a field? Thanks in advance.

1 Answers  


Write a program to find factorial of a number using functions

1 Answers   Peerless,


In OB52 , How to define two open posting period, Like only 5 and 8 posting should be open.. should not open 6 and 7..period..

1 Answers  


Categories