This is the required link.I think it is because of constraints and the sort function but not understanding how to proceed further.
Getting TLE in 1 case
Your code is perfect! there’s some issue at backend!
try submitting it here 
https://hack.codingblocks.com/app/practice/1/157/problem
mark resolved is doubt is clear