Mutual Translation Routes
Problem
DataFrame `route` has columns `src` and `dst`, one row per directed route. A pair is mutual when a distinct row exists for both directions: row (a -> b) and a different row (b -> a). This requires two separate rows, so a self-loop (x -> x) is mutual only when it appears at least twice. Report each mutual pair once, normalized so `src <= dst`.
Return columns `src`, `dst`, sorted by `src` then `dst`.
Input data
Example rows — the live problem includes the full dataset.
| src | dst |
|---|---|
| 10 | 20 |
| 20 | 10 |
| 30 | 40 |
| 50 | 50 |
| 50 | 50 |
Expected output
Your answer should return 2 rows with the columns src, dst.
Starter code (Pandas (Python))
import pandas as pd
def mutual_translation_routes(route) -> pd.DataFrame:
# Your code here
return routeSolve 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