Great substrings

Below is the problem statement
I solved it in o(N^2)
Is there any optimal solution to it?

Thanks in advance

Share the link

Sorry i dont have any link to the question
This question is from hacker earth Alefedge Development hiring contest

Contest is still live. Ask after 7th March.

So there will be same set of questions throughout the challenge.

I am not sure of that. But there maybe common problems. Better to ask after it ends. Why give some candidate an advantage.

Okay Bro

Bro Do you have solution for it