Iscar interview question

Sql question and one backtracking