mockers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Missing and Repeated :Vinisha Ma'am

+2
ramthegreatcv
ballu
6 posters

Go down

Missing and Repeated :Vinisha Ma'am Empty Missing and Repeated :Vinisha Ma'am

Post  ballu Sun Feb 01, 2009 10:17 pm

in array there are numbers only upto n
one is repeated and one is missing
find both the numbers
ballu
ballu

Posts : 58
Join date : 2009-02-01

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty Re: Missing and Repeated :Vinisha Ma'am

Post  ramthegreatcv Mon Feb 02, 2009 2:25 am

use the following method:

mark the missing number as M and the duplicated as D

1) compute the sum of regular list of numbers from 1 to N call it RegularSum

2) compute the sum of your array (the one with M and D) call it MySum

now you know that MySum+M-D=RegularSum

this is one equation.

the second one uses multiplication:

3) compute the multiplication of numbers of regular list of numbers from 1 to N call it RegularMultiplication

4) compute the multiplication of numbers of your list (the one with M and D) call it MyMultiplication

now you know that MyMultiplication=RegularMultiplication*D/M

at this point you have two equations with two parameters, solve and rule!
ramthegreatcv
ramthegreatcv

Posts : 55
Join date : 2009-01-30
Age : 35

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty Re: Missing and Repeated :Vinisha Ma'am

Post  $corpion Mon Feb 02, 2009 2:43 am

sexy Ramp...mast solution..
$corpion
$corpion

Posts : 25
Join date : 2009-01-30
Age : 37

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty @ramu

Post  mnnit.rahul Mon Feb 02, 2009 2:47 am

your case fails when sum/multiplication exceed the integer limit there exists better solutions for it

mnnit.rahul

Posts : 51
Join date : 2009-02-01

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty Re: Missing and Repeated :Vinisha Ma'am

Post  udita Mon Feb 02, 2009 9:00 am

as the numbers are upto n we can use count sort ..
in the array that saves the number of occurences of each number
1. value of count for the repeated number will be 2 and
2. for the missing number will be zero.

udita

Posts : 11
Join date : 2009-02-01

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty Re: Missing and Repeated :Vinisha Ma'am

Post  Admin Mon Feb 02, 2009 9:40 am

this is very popular interview question, the actual version goes like.
1) no Auxillary space(map,array etc) to be used.
2)O(n) time complexity.

LIMIT EXCEEDED:i agree that the limit might exceed.but this is the answer the interviewer is expecting from us.
NO MAPS:so map etc cannot be used.and for questions like that it is a trivial ans,not much impressive.for that matter take the question from subjective paper.that was solved by XOR,not by maps.

Admin
Admin

Posts : 47
Join date : 2009-01-29

https://mockers.forumotion.com

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty @ramu

Post  mnnit.rahul Mon Feb 02, 2009 3:25 pm

yes one solution is we can solve it by xor
but explain to karo ramu bhai


there exist a solution without xor also which even doesn't use single extra variable

mnnit.rahul

Posts : 51
Join date : 2009-02-01

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty @everyone

Post  ballu Mon Feb 02, 2009 7:18 pm

xor se kaise karoge bhaiya?? batao Crying or Very sad
ballu
ballu

Posts : 58
Join date : 2009-02-01

Back to top Go down

Missing and Repeated :Vinisha Ma'am Empty Re: Missing and Repeated :Vinisha Ma'am

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum