β¨ Algorithm
const backtrack = (cur, OTHER_ARGS...) => {
if (BASE_CASE) {
// do some logic
return;
}
let res = 0;
for (ITERATE_OVER_INPUT) {
// modify the current input
cur.push(CHANGE);
ans += backtrack(cur, OTHER_ARGS...);
// undo the modification of the current state
cur.pop();
}
return res;
}
backtrack([], ...);