Code RoomBeautiful permutations
MediumPrep Room Coding #475

Beautiful permutations

CodingAlgorithms & data structuresMid–Senior~22 min

A permutation perm of 1..n is 'beautiful' if for every 1-indexed position i, either perm[i] is divisible by i or i is divisible by perm[i]. Return the number of beautiful permutations of 1..n. 1 <= n <= 12.

Implement
beautiful_arrangement(n: int) → int
Examples
in[2]out2
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 22 min
InputExpectedGot
[2]2not run yetsample