Time limit exceeded

i am getting tle through this code.
here is my code

try using a hashmap instead of an array