LinkedIn interview question

Standard Algorithm and DS. Medium difficulty