Backtrack solution