Checking if an array of integers is a set.

A set must pass on these three conditions: 
– All values are positive 
– Sorted 
– Non-duplicates 

bool isSet(int arr[],int n){
int i=0;
while(i<n){
if(arr[i]<0)
return false;
if(i==0){
i++;
continue;
}
if(arr[i]<=arr[i-1])
return false;
i++;
}
return true;
}
view raw isSet.cpp hosted with ❤ by GitHub

Leave a comment