I decided to use it and an additional array. Here "len" is the length of the array.
int findMin(int *arr,int n,int len) { int *hash; if(len==0) {return -1; //fail } hash=(int*)calloc(len,sizeof(int)); //hash function I'm using is f(x)=f(x)-n; int i; for(i=0;i<len;i++){ if(arr[i]>n && arr[i]<len+n){ //because max element can't be more than n hash[arr[i]-n]++; } } i=1; while(i<len){ if(hash[i]==0) return len+i; i++; } return len+n+1; }
The order of this soul is the operating hours of O (n) and O (n).
source share