Backtracking- Class Assignment Problem


I am getting TLE

I think this might be a better approach: https://ide.codingblocks.com/s/313443