Chegg interview question

Ds and algorithms question