Skip to the code
cf.
+25 XP

#301 Compatible Slot Orders

medium

A carousel has n slots numbered 1 to n, and n cards numbered 1 to n. Each slot gets exactly one card. A card fits a slot when the card number divides the slot number, or the slot number divides the card number.

Write countCompatibleOrders(n) that returns how many ways there are to place all cards so that every card fits its slot.

Example 1

Input: n = 2
Output: 2

Both [1, 2] and [2, 1] work, because 1 divides everything and 2 divides 2.

Example 2

Input: n = 1
Output: 1

Card 1 in slot 1.

Constraints

  • 1 <= n <= 12
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).