Problem in Bridges

Please help me find the mistake in the solution.
Also please explain the question.i dont understand the meaning of: The ith point on one side should map to the only ith point on the other?

Hey correction is on line 30 : if(arr[i].first >= arr[j].first && arr[i].second >= arr[j].second)
Btw u dont have to add 1st condition as u already sorted the array.

And

this means that ith index element of 1st array is starting position and ith index index element of 2nd element is ending position for ith bridge.

still getting the wrong ans

Please share your code again & please recheck once because with the change I mentioned your code is working perfectly on my side.

I applied the logic as: first sort the array acc to one side then find the longest increasing subsequence from other side

@abhir26 share your code again.

@abhir26 your Logic is correct.

here is the code link

Hey @abhir26
U haven’t done the changes I suggested
line 30 should be if( arr[i].second >= arr[j].second)
You also have to consider equal elements

Ohh sorry I forgot to put = sign in condition. Thanks for resolving!

1 Like