I am getting TLE in 1 test case. What am i missing here ?
Sir I am getting TLE in O(n) solution
that’s because the input data is very large so you have to use scanf for reading input insead of cin as scanf is faster than cin
In case of any doubt feel free to ask 
if you got the answer mark your doubt as resoved
Sir i updated my code as per your suggestions. Its still stuck in TLE.
hey , there is a time precision issue in this problem try submitting your solution two three times it will pass all test cases ( your solution passes all test cases in my computer)