mine holds the page count of each of your books, and theirs holds the page counts of your friend's books. Right now your page totals differ.
You want to trade exactly one book each so that afterwards you both own the same total number of pages.
Return [a, b], where a is the page count of the book you give away and b is the page count of the book your friend gives you. If several trades work, pick the one whose book appears earliest in mine. At least one valid trade is guaranteed.mine=[5, 2], theirs=[3] → [5, 3]
You have 7 pages and your friend has 3. Give away the 5-page book and take the 3-page one: you both end up with 5.
mine=[4, 6, 1], theirs=[2, 5] → [4, 2]
The totals start at 11 and 7. Trading 4 for 2 gives 9 and 9; no other trade works.
mine=[3, 1, 4], theirs=[2, 2, 4, 6] → [3, 6]
The totals are 8 and 14, so the book you get must be 3 pages longer than the one you give. Both 3 ↔ 6 and 1 ↔ 4 work; the 3-page book comes first in your list, so the answer is [3, 6].
mine=[5, 2], theirs=[3]
[5, 3]
Run checks the first 3 tests in your browser. Submit checks all 24 tests on the server, hidden ones included.