Sort and take window of 2 while traversing,
stop when the elements in the window do not match.The first one will be the
non-repeated assuming only one such number exist in the array.
complexity:o(nlogn)
PS:Another possible solution is =
1. Form a BST.Add extra variable count to the node.
2.while
code for my *second *solution
http://www.ideone.com/oxDql
http://www.ideone.com/oxDqlPoint out any bugs if you find.
On Sat, Jul 9, 2011 at 12:43 PM, saurabh singh saurab...@gmail.com wrote:
Sort and take window of 2 while traversing,
stop when the elements in the window do not match.The
@saurabh.shouldn't be 5 also be in the outputi think u forgot to
print the root value
On Sat, Jul 9, 2011 at 9:27 PM, saurabh singh saurab...@gmail.com wrote:
code for my *second *solution
http://www.ideone.com/oxDql
http://www.ideone.com/oxDqlPoint out any bugs if you find.
On
@John 5 is the number of inputs that the program will be expecting.Its not
part of the array.
On Sat, Jul 9, 2011 at 9:35 PM, John Hayes agressiveha...@gmail.com wrote:
@saurabh.shouldn't be 5 also be in the outputi think u forgot to
print the root value
On Sat, Jul 9, 2011 at 9:27
Are their any space or time constraints ?
On Jul 8, 3:21 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote:
is there anyting special about the array???
or it is aribitary array??
On 7/8/11, Dumanshu duman...@gmail.com wrote:
given an array of intergers. find the any integer that occurs only
no constraints but try to give the optimized solution and plz no
hashing.
On Jul 8, 7:02 pm, Dumanshu duman...@gmail.com wrote:
given an array of intergers. find the any integer that occurs only
once. Others might occur any no. of times.
--
You received this message because you are
try sorting then if hashing
On 7/8/11, Dumanshu duman...@gmail.com wrote:
no constraints but try to give the optimized solution and plz no
hashing.
On Jul 8, 7:02 pm, Dumanshu duman...@gmail.com wrote:
given an array of intergers. find the any integer that occurs only
once. Others
my solution solve the problem in O(n) time but requre space comlexty n.
solution:
1. take an temp array and initialize it elements with zero;
int temp[n]={0};
2.increment the count of the element of temp which is appear when loop
through the given array say a[n];
for(int i=0;in;i++)
Well your method can solve this problem when the range of the array elements
is given.
Try considering 2*10^9 as one of the element of the array, how big your temp
array be?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this
a[]={2,2,3,3,3,4,4,5,6,6,7}
size of array = n
if not sorted than sort
for(i=1;in-1;i++) //check for elements with index 1 to n-2
{
if(a[i]!=a[i-1] a[i]!=a[i+1])
print(a[i]);
}
//now check for index 0 and n-1
if(a[0]!=a[1])
print(a[0]);
if(a[n-1]!=a[n-2])
10 matches
Mail list logo