Problems > Count the Derangements > Editorial

Count the Derangements — Solution & Editorial

Back to the Problem

Recurrence Dn = (n−1)(Dn−1 + Dn−2) with D0 = 1, D1 = 0.

Complexity: O(N)