Saviynt interview question

DSA question. Needed multiple approaches to solve it