All pref test giving ttl

Please guide me on how to optimize this code further because it takes only O(N) time.

I went through your code. It looks like O(N) but isn’t . You are passing the vector<int> arr by value every time which causes the value to be copied everytime (increasing the complexity to O(N^2). Pass the vector by reference using vector<int> &arr to resolve the issue.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.