Sorry but searching thru an array "of all permutations of length n" doesnt make sense. If the tested string is shorter than n it will be a member by definition (modulo side criterias like repetition). If its just about counting use a hash like shown and a logical test.