Can i do this question in O(n) complexty

if yes,please give some hint to solve it

Yes you can do.
You can use the floyd algo or the hashing based approach.
Refer the approaches from here