TMRW interview question

Asked to solve dsa question