Code RoomPartition into pairs
HardPrep Room Coding #844

Partition into pairs

CodingAlgorithms & data structuresSenior–Staff~35 min

You have n people (n even) and an n x n symmetric boolean matrix compatible where compatible[i][j] is 1 if person i and j can be paired. Count the number of ways to partition ALL people into n/2 compatible pairs (each person in exactly one pair). Two partitions are the same if they use the same set of pairs. Return the count. 2 <= n <= 14, n even, compatible[i][i]=0.

Implement
count_perfect_matchings(compatible: list[list[int]]) → int
Examples
in[[[0,1],[1,0]]]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[[[0,1],[1,0]]]1not run yetsample