Santa Banta
Medium Accuracy: 51.04% Submissions: 349 Points: 4

Santa is still not married. He approaches a marriage bureau and asks them to hurry the process.
The bureau checks the list of eligible girls (n) and hands it over to Santa.
Santa being conscious about his marriage, determined to find a girl with maximum connections so that he can gather more information about her.
Accordingly, he looks to figure out the maximum number of girls (from the list) who know each other to achieve the above purpose.
In order to finalize the girl, he needs to find the Kth prime.
Where k = largest group of girls who know each other.
Considering Santa's poor knowledge in Maths, he seeks Banta's help for the answer.
Now you, being a fan of Santa Banta Jokes, take this prestigious opportunity to solve the problem.

In case no of connections is zero, print "-1".

Note :
Suppose girl "a" knows girl "b" and girl "b" knows girl "c", then girl "a" also knows girl "c".
Transitivity holds.
Consider 1 composite no.

Example 1:

​Input : arr[] = {{1,2},{2,3},{3,4},{4,5},
N = 10 and M = 6
Output : 11
Here in this graph there are 4 groups. 
In 1st group: (1 -> 2 -> 3 -> 4 -> 5) are 
there. In 2nd group: (6 -> 7) are there.
In 3rd group: (8) is there.
In 4th group: (10 -> 9) are there.
In these 4 group the maximum number of 
value is 5. So, K = 5 and the 5th prime number 
is 11. Return 11.

Example 2:

Input : arr[ ] = {{1, 2}}
N = 2 and M = 1 
Output : 3

Your Task:

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function helpSanta() that takes a number of girls (n), a number of connection (m), adjacency list of girls connections (g), and return the Kth prime no if there are no connections then return -1. The driver code takes care of the printing.

Expected Time Complexity: O(N + M).
Expected Auxiliary Space: O(N + M).


Each new line of the output contains Kth prime no.


1 ≤ n ≤ 105
0 ≤ m ≤ 105
1 ≤ u, v ≤ n

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Santa Banta

Output Window