Please describe in detail what the function is supposed to do. A permutation is a rearrangement of a set of items and that isn't want this is doing. Is it just returning true if there are no duplicates?
What should it return for these inputs:
{}
{1}
{ 18 300}
{100 101 102}
{1 2 5}
{1 2 3 4 1}
the isPermutation function which OP wrote returns true, if the n size array contains all of 0 to n-1; otherwise returns false.
OP probably wants different outcome.
To see if an array of N elements contains exactly the values 0 to N-1 you don't need to sort the auxiliary array. In fact, the aux array can just indicate whether you've seen the item already:
1 2 3 4 5 6 7 8 9 10 11
bool isPermutation(constunsigned a[], unsigned elements)
{
vector<bool> alreadySeen(elements, false);
for (unsigned i=0; i<elements; ++i) {
if (a[i] >= elements || alreadySeen[a[i]]) {
returnfalse;
}
alreadySeen[a[i]] = true;
}
returntrue;
}