Still failing perf-test-5

Continuing the discussion from Failing Perf-Test-5:

Thank you @Sumanth_Uppala for pointing out the error. I fixed it but the test case still fails.

I have a suspicion it can be one of two things :

  1. The way I am handling distance > k is wrong.
  2. The way I am calculating the order from the license plate is wrong.

Would be thankful if you could look at my code again and see where I could be going wrong.

Hey @S4G4R you are right, the way you are handling distance > k is wrong.

How do you decide which pointer to move?

Let’s solve much simpler problem, Assume we are working with two sorted arrays and our goal is to find the first pair whose difference <= k.

K = 3
Array A = [9, 15, 19]
Array B = [20, 21]
Output : 19 and 20

Let’s say i and j are two pointers on A and B arrays respectively on index 0.

Now A[i] + A[j] = 29 and 29 is greater than K(3) so which pointer should we move to reduce the difference and find that first pair whose diff <= k.

We should always move the pointer which is pointing to smaller value so that our difference will reduce. In this case we should move i pointer.

Got the cue? Coming back to original question you should move the pointer based on the values of registration numbers of Good and Bad cars.

Happy Coding :slight_smile:

1 Like

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.