Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Permutation Wheel

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Choose every unused value for the next slot: The Permutation Wheel.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Permutation backtracking matches the clues
  2. 2Keep this true after every move: path contains distinct chosen indices and has one value per completed position
  3. 3Reach the result within O(n times n!) output time

Rules and pressure

  • Target cost: O(n times n!) output time
  • State rule: path contains distinct chosen indices and has one value per completed position
Lesson 1 of 3

Live algorithm trace

Permutation backtracking

Complete execution
1 of 6
1
choice
2
3
0
1
2

The first position may choose any sorted value.

1if path length is n: record
2for each index
3skip index when already used
4mark used and append value
5recurse for next position
6pop and unmark
path = []used = none
Truth to preserve / Cost target
Truth to preserve

path contains distinct chosen indices and has one value per completed position

Cost target

O(n times n!) output time

Each recursion depth owns one output position. Try every unused value there, mark it during the child search, then unmark it for the next sibling.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead