Failing only 1 test case i.e perf-test-19

Can the TA help me with what I am missing in this approach?

Hey @tanujsharma1412 Your code is O(N^2) complexity and hence fails for the performance case.

Optimize your code to Linear time(expected complexity for this based on the given constraints) so that all the test cases will pass.

It has been explained numerous times in multiple sessions that only write code if you are sure you have got the optimal solution that satisfies the given constraints.

Encourage you to understand the relation between constraints and expected complexity based on the constraints.

Hint for this problem: Try greedy approach.

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.