
Given an array of integers that may contain duplicates, generate all unique permutations. Ensure no duplicate permutations are returned even if some values occur more than twice. Describe your algorithm (e.g., backtracking with frequency counts), prove correctness, and analyze time and space complexity.