Dsa
Two Pointers
Easy
Fiber Optic Alignment
Two fiber optic cables are laid side-by-side. Each cable has signal boosters at various fixed distances from the start. To minimize interference, engineers need to find the smallest distance between any booster on Cable A and any booster on Cable B.
Input Format:
Line 1: Two integers N and M, the number of boosters on Cable A and Cable B respectively.
Line 2: N space-separated integers representing booster positions on Cable A (sorted).
Line 3: M space-separated integers representing booster positions on Cable B (sorted).
Output Format:
A single integer representing the minimum absolute difference between any two booster positions.
Example:
Input:
2 3
10 50
15 42 65
Output:
5
(Explanation: |10 - 15| = 5, which is the smallest gap.)
Key concepts
two_pointerssorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now