This challenge like any other challenges is to test your ability, you skills at programming.
Quote:
I could only get the brute force method for the question.
There is different levels in brute force. You should show your code.
On 'geeksforgeeks.org', challenges are notoriously difficult and only your knowledge of algorithms and data structures can help you.
Generally speaking, brute force is the first solution one find, then a study of what is useful and what can be removed is the lead to a better solution.