Hackerearth: Complete the Syllabus

Copied the code from someone’s solutions:

code from editorial: