I got the correct answer:

If it is a valid array, sum of all elements in the array = value
calculated using arithmetic progression formula

In this case

Sum of arithmetic progression = (n/2)[2*a+(n-1)*d}
where a = min of the array
n = number of elements
d = 1

If this value is equal to sum of all the elements in the array then it
is  a valid array

On Dec 10, 6:44 am, ADITYA KUMAR <aditya...@gmail.com> wrote:
> @jai
> yeah, it can be done using count sort logic
> but that will take O(n) extra space
>
> which can be avoided by using XOR.
>
>
>
>
>
> On Fri, Dec 10, 2010 at 3:34 AM, jai gupta <sayhelloto...@gmail.com> wrote:
> > Algo:
> > In first traverse find the min and the max values.
> > if (max-min)  not equals (N-1)
> > return false
> > In next traverse map each in a hashtable of size N where index=key-min. Now
> > in case of collision return false
> > return true
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups­.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Regards
> Aditya Kumar
> B-tech 3rd year
> Computer Science & Engg.
> MNNIT, Allahabad.- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to