HackerEarth K Friends problem solution - TheCScience