Unlock problem https://ide.codingblocks.com/s/188554

I got TLE for this problem so can u give me the reason why i got TLE and what are ways to optimize my code?

@meetsoni01041996
hello meet ,
ur solution time complexity is O(n^2) thats why u are getting tle.
to optimise it use map.

image