Saviynt Interview Question

DSA question. Needed multiple approaches to solve it