HackerRank is a Great place to learn coding. But it will a hard time for beginers to deal with some challenges.I faced that difficulty and this is a help from me to new learners.Don't just copy and paste my code ,that will not teach you anything.Just look at it, think how did I do that, Correct your Mistakes, and then build your own one.It will make you a great programmer!
I hope there's no need to add the question as the user can google the question name on CPP file .