Question bank › Two Pointers
Dsa Two Pointers Easy

Bilateral Power Balance

Two teams (North and South) are pulling a weight. Each member has a power level. You need to pick exactly one member from the North team and one from the South team such that the sum of their power levels is as close as possible to the target weight T. Return the absolute difference between the best possible sum and T. Input Format: Line 1: N (North size), M (South size), T (Target) Line 2: N sorted power levels for North Line 3: M sorted power levels for South Example: Input: 3 3 15 2 5 10 3 8 12 Output: 0 Explanation: North 2 + South 12 = 14 (diff 1). North 5 + South 12 = 17 (diff 2). North 2 + South 12 = 14. North 5 + South 10 (Wait, South is 3, 8, 12). North 5 + South 8 = 13 (diff 2). North 10 + South 3 = 13. North 10 + South 8 = 18. North 2 + South 12 = 14. North 5 + South 12 = 17. The sum 15 is possible via North 2 + South 12? No. 5 + 10? No. Let's recheck: North [2, 5, 10], South [3, 8, 12]. Target 15. North 2 + South 12 = 14 (diff 1). North 5 + South 8 = 13 (diff 2). North 10 + South 3 = 13. North 5 + South 12 = 17 (diff 2). Best sum is 14 or 17? Wait, 2+12=14 and 10+5 is not possible. 10+3=13, 10+8=18. Closest to 15 is 14 (diff 1).

Key concepts

two_pointerssorted_arrays

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.