How csn the problem be solved using searching and sorting

provide me the code with comments using searching and sorting