SPOJ BROKEN WA

I am solving the Broken keyboard problem . I used the sliding window approach O(n) solution. but i’m getting wrong answer. Can anybody tell me where i went wrong ?. thanks in advance.

my solution: EiweVp - Online C++ Compiler & Debugging Tool - Ideone.com
problem : SPOJ.com - Problem BROKEN

your code gives wrong output for following case:
4

abcdcefe

0
you might have missed some minor test cases. The logic is correct :slight_smile: