u can also compute sum in 1 iteration along with min, max. now max * (max+1) / 2 - min * (min - 1) / 2 = sum if it is true then answer is yes
On Thu, Dec 9, 2010 at 6:00 PM, Terence <[email protected]> wrote: > A[1..N] is Valid <=> max{A[i]} - min{A[i]} == N-1 > > > On 2010-12-9 20:16, Prims wrote: > >> Given array A with n elements, give an algorithm for finding whether >> it’s a valid array or not? >> Array is called Valid if all the numbers appearing in A [1...N] are >> consecutive numbers. >> >> Example: A={5,3,4} is a valid array >> A={3,7,5,4,6} is a valid array >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
