MEDIUMasked at 1 company

Find the Derangement of An Array

A medium-tier problem at 42% community acceptance, tagged with Math, Dynamic Programming, Combinatorics. Reported in interviews at IXL and 0 others.

Founder's read

A derangement is a permutation where no element sits in its original position, and IXL has asked this problem. You'll see it listed as medium difficulty with around 42% acceptance, which means most candidates either don't recognize the combinatorial pattern or get tangled in the recurrence relation. This isn't a brute-force problem. The trick is a compact DP formula that most people won't see without studying it first. If you hit this live and blank on the math, StealthCoder surfaces the solution in seconds, invisible to the proctor, so you move on instead of timing out.

Companies asking
1
Difficulty
MEDIUM
Acceptance
42%

Companies that ask "Find the Derangement of An Array"

If this hits your live OA

Find the Derangement of An Array is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.

Get StealthCoder
What this means

The core insight is that derangements follow a recurrence: D(n) = (n-1) * (D(n-1) + D(n-2)). The math comes from two cases when placing the element at position 1: swap it into someone else's spot (creating a smaller derangement), or swap and recurse. Most candidates try brute-force permutation checking or miss the relationship between D(n) and the previous states. The DP path is straightforward once you see the pattern, but the combinatorics behind why that formula holds is where people stumble. This crosses Math, Dynamic Programming, and Combinatorics, and the intersection is where the problem lives. StealthCoder cuts through the theoretical noise and gives you a working implementation when the pattern doesn't click under pressure.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find the Derangement of An Array recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find the Derangement of An Array interview FAQ

What makes this problem harder than standard DP?+

It's not the DP mechanics, it's the math setup. You need to recognize the recurrence relation from first principles, not just fill a table. Most DP problems give you clear state transitions. This one requires you to reason about why swapping produces that specific formula.

Is this still asked at tech companies?+

IXL has it in their interview reports. It's a lower-frequency ask overall, which means fewer candidates have drilled it. If it shows up in your OA, you're at an immediate disadvantage unless you've seen the pattern before.

What's the most common mistake?+

Trying to generate all permutations and check validity. That's O(n!), not DP. The second mistake is confusing derangement with other combinatorial structures. Nail down the definition: every position must differ from the input.

How do I derive the recurrence during an interview?+

Fix position 1. Element i can go there. If i goes to position 1 and 1 goes to position i, you have a smaller derangement of (n-2) elements. Otherwise, treat 1 as if it's in position i's slot, giving you D(n-1). This logic gets you to the formula.

Does this relate to other combinatorics problems?+

Yes. It connects to inclusion-exclusion principle and subfactorial notation. Understanding those helps, but they're not required for the DP solution. The recurrence is sufficient and faster to code under time pressure.

Want the actual problem statement? View "Find the Derangement of An Array" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.