Math Fundamentals18 sections · 814 units
Open in Course

Permutations II - Implementation

(Duplicate pruning)

Time complexity: O(n × n!). Sorting is O(n log n), then you generate unique permutations.

Space complexity: O(n) for recursion and used array.

The key: sorting + pruning condition eliminates duplicates cleanly.