ABC interview question

2 DSA Q Med, Hard