String window Problem

can i use brute force approach to solve this problem ??
will the IDE will accept my code if code using brute force approach