I would like to say a few things:
- Rishup already pointed out, test cases are weak. Given the constraints, a O(n2) solution should not pass.
- The Python3 Solution is not mine.
- Python has different time multiplier (which might have given edge over cpp solution)
- Finally, the constants, they are ignored while calculating time complexity, but still play a major role. Read here
I know, it is strange for the same complexity to be accepted in one language and rejected in another, but maybe you should focus on improving the complexity from O(n2)