Re: [algogeeks] Sort - Consecutive Array in O(n)

2011-07-06 Thread sunny agrawal
@ Sathaiah Dontula i think this won't work Because product of m consecutive integers is divisible by m! but reverse is not true ie. if product of m integers is divisible by m! then they are consecutive ?? correct me if i am wrong!! On Wed, Jul 6, 2011 at 12:55 PM, Sathaiah Dontula wrote: > How a

Re: [algogeeks] Sort - Consecutive Array in O(n)

2011-07-06 Thread Sathaiah Dontula
How about doing like this ?. Without loss of generality, I can assume that numbers starts from 1 (if not, if it starts from ZERO, add by 1 to all the numbers, if it is negative, find the min value, assume it is X, add by (-X)+1)) Now assume numbers are M, compute the product of the numbers and c

Re: [algogeeks] Sort - Consecutive Array in O(n)

2011-07-05 Thread Anantha Krishnan
Check this *int isconsecutive(int a[], int n) {* *if (n < 1) {* *return 0;* *}* *int max = a[0], min = a[0];* *int i = 0;* * * *int *hash = (int*) calloc(n, sizeof (int));* * * *//find min and max from the array* *for (i = 1; i < n; i++) {* *if (a[i] < m

[algogeeks] Sort - Consecutive Array in O(n)

2011-06-24 Thread ross
Given an array, A, find if all elements in the sorted version of A are consecutive in less than O(nlogn). eg: A: 5 4 1 2 3 on sorting 1 2 3 4 5 all elements are consecutive -- true A: 1 9 2 22 on sorting 1 2 9 22 all elements are NOT consecutive - false -- You received this message because you ar