const solution = (N, M) => {
const temp = Array.from({ length: M }, () => 0);
const answer = [];
const DFS = L => {
if (L === M) {
answer.push([...temp]);
} else {
for (let i = 1; i <= N; i++) {
temp[L] = i;
DFS(L + 1);
}
}
};
DFS(0);
return answer;
};