Only one test case is passing!

@S19LPPP0132 I am unable to get your approach but there is some problem in your logic.
Consider the test case:
Input:
4 1
0 2

Expected Output:
5

Your Output:
4

5 ways of choosing a pair:
[0,1] [0,3] [1,2] [1,3] [2,3]

In one of the graphs webinar of Prateek Bhaiya, he has discussed about a problem named “Journey to the Moon” which is similar to this problem. Refer that video and then try to solve this.

Hope this helps :slightly_smiling_face:

1 Like

I have corrected the mistake , still only one tc is passing .

Consider test case:
10 7
0 2
1 8
1 4
2 8
2 6
3 5
6 9

3 sets {0,1,2,4,6,8,9} {3,5} {7}
So answer should be 23. But your code is giving 29.


Refer this code. If you are not able to understand the approach, then you can refer the discussion on " Journey to the Moon" problem in one of the webinar.

1 Like

Thanks alot !!
I got the mistake.