@sarath:
it is not specified that the range is from 1 to n..it may look like this:
1 99 2 99
here you cant access a[99]..
On Fri, Sep 16, 2011 at 7:28 PM, sarath prasath wrote:
> this is one is the elegant solution i came across
> if u got an element just go to the elements index and mark the v
this is one is the elegant solution i came across
if u got an element just go to the elements index and mark the value to its
negative...
say for eg:
if u got a[i]=9;
then go to a[9] and make it as
a[9]=-a[9];
then do like this for all the elements in the array
so now u can get the logic to how to
1: use bit array(hashing) then only it is possible in O(n)
On Fri, Sep 16, 2011 at 12:04 PM, tech coder wrote:
> @ akshat read the question properly before posting such solution
>
>
> On Wed, Aug 31, 2011 at 12:27 PM, Akshat Sapra wrote:
>
>> Solution:
>>
>> arr[n],sum = 0;
>>
>>
>> for ( int
@ akshat read the question properly before posting such solution
On Wed, Aug 31, 2011 at 12:27 PM, Akshat Sapra wrote:
> Solution:
>
> arr[n],sum = 0;
>
>
> for ( int i = 0 ; i < n; i++ ) {
>sum ^= arr[i];
> }
>
> print sum; // required number
>
> --
>
>
> Akshat Sapra
> Under Graduat
*//this method can be applied only when
the value of elements in array are not very large
int count[];
for(i = 0 to n-1)
{
if(count[arr[i]] == 1)
printf(" %d ", arr[i]);
else
count[arr[i]]++;
}*
..
On Wed, Aug 31, 2011 at 12:38 PM, Yuchen Liao wrote:
> Hi Akshat,
>
>
Hi Akshat,
I think that you are wrong here. For example, I have 1, 1, 2 in the
array. The output will be 2. But not 1.
On Wed, Aug 31, 2011 at 1:57 AM, Akshat Sapra wrote:
> Solution:
>
> arr[n],sum = 0;
>
>
> for ( int i = 0 ; i < n; i++ ) {
>sum ^= arr[i];
> }
>
> print sum; //
Solution:
arr[n],sum = 0;
for ( int i = 0 ; i < n; i++ ) {
sum ^= arr[i];
}
print sum; // required number
--
Akshat Sapra
Under Graduation(B.Tech)
IIIT-Allahabad(Amethi Campus)
--
sapraaks...@gmail.com
akshatsapr...@gmail.com
rit2009...@iiita.ac.in
If the numbers in the array continuous .. then it is very simple by using
Arithmetic Progression . we can sum up the all the numbers in an array and
subtract Arithmetic Progression sum..we will get...O(n)..
or
in one trace we can find min and max numbers in that array..
bitset <(max-min)> duplic
You are given an array. One integer is in the array twice and others
are unique. Find that no. O(n) Solution
--
Regards,
Navneet
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com