Useful math
- Total number of subset for a given array is
2^n - Combinations:
Permutations ^43a0c7
- Total of permutations for a given array:
n!/(n-k)!wherekis the number of element we are trying to arrange ^082db8 => Permutation of the whole arrayn! - When we want the next greater number using the same digits as 12543, we want to make the smallest possible increase by changing as few digits as possible, starting from the right. The same principle applies to permutations. ^2b285a
- Notice that
543is already the largest possible arrangement - Pick
2and then pick3as we are trying to make the smallest increase - We swap
2and3to get13542but this is not the smallest increase - We have to sort everything after the swap (after
3) to make sure the right portion is smallest possible =>13245 - This is actually happen if we do it by ourselves
- Notice that