Let’s define the requirements for this algorithm. We are given two sets of integers. The idea is to check if the sets are permutations of each other. If they are, return YES; otherwise return NO.

First let’s make sure we agree with the definition of permutation. For the sets to be permutations we must have the same number of elements in both sets. Each set must have the same counts for each entry. For example if the sets are:

1 2 3 4 5 6

6 5 4 3 2 1

Then we would return **YES**. Both sets have the same length (six in this case) the numbers are the same on both sets, and the count of each number matches (one in this case).

7 6 5 0 9 7

7 6 1 0 9 7

Given that 5 is in the first set, but not in the second and 1 is in the second, but not in the first, these are not permutations of each other so we would return **NO**. Continue reading “Is Permutation”