Collaborator Pairs With No Shared Collaborator
Problem
A DataFrame `collabs` records direct collaborations between researchers as undirected pairs: each row has two researcher ids `person_a` and `person_b` who have worked together. A collaboration goes both ways, so if `person_a` worked with `person_b`, then `person_b` also worked with `person_a`.
Find every collaboration pair where the two researchers share no common collaborator -- there is no third researcher who has worked with both members of the pair. Return a DataFrame with columns `person_a` and `person_b` for each such pair, ordered by `person_a` then `person_b`.
Input data
Example rows — the live problem includes the full dataset.
| person_a | person_b |
|---|---|
| 1 | 2 |
| 2 | 3 |
| 2 | 4 |
| 1 | 5 |
| 6 | 7 |
Expected output
Your answer should return 2 rows with the columns person_a, person_b.
Starter code (Pandas (Python))
import pandas as pd
def lonely_pairs(collabs) -> pd.DataFrame:
# Your code here
return collabsSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock