Can anyone tell where am i wrong. Link to my solution
Can you explain your Logic that you used because it will be easy to debug thereafter
After sorting interval in ascending order of their first element(and in case of tie in ascending order of their second element) eg say input was [1, 3], [1,10], [1, 4], [3, 10]
then after sorting we have [1,3], [1,4],[1,10],[3,10].
Now first i took sum of f-interval[n-1].second+interval[0].first
After that i am starting from second interval
and checking 3 conditions
- Its 1st element < previous interval’s second element and its 2nd element < previous interval’s second element. Then do nothing
- Its 1st element < previous interval’s second element and its 2nd element > previous interval’s second element. Then i will only point to index of this interval(which i am storing in variable name curr) for use in 3rd case
- Its 1st element > previous interval’s second element. Then add its first element - second element of currently pointing interval and updating the pointer to index of this interval(which i am storing in variable name curr)
On my machine, your solution gives YES
for the following test input:
1
3 1 1
1 1
0 1
0 0
2 Likes
Actually problem was in my sorting of vector of pair and now it passes the test case you gave but now the solution has got even worsen See here.
1 Like
1
4 2 3
0 0
1 1
0 3
0 2
1 Like
How can the invigilator’s interval be [3,1] ?
Sorry I was wrong there.
1 Like