Use backtracking, since we need to return a array, it is better to use void to handle that rather than return type function.
- Check current situation is valid or not, check previous index is volatile our current wants to insert index by (previous_index != i && previous_index - (current_layer - previous_layer) != i && previous_index + (current_layer - previous_layer) != i))
- go to next layer
It is different than we handle return type, since return type first goes to next layer than check the validation.
Error:
- Do not return when meet the end
- We only go to next layer when all previous layer does not volatile